chaos
This commit is contained in:
parent
eb7f9e67b5
commit
7de7fb6cff
228
ws/ws.pb.go
Normal file
228
ws/ws.pb.go
Normal file
|
@ -0,0 +1,228 @@
|
||||||
|
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||||
|
// source: ws/ws.proto
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package echoserver is a generated protocol buffer package.
|
||||||
|
|
||||||
|
It is generated from these files:
|
||||||
|
ws/ws.proto
|
||||||
|
|
||||||
|
It has these top-level messages:
|
||||||
|
WSRequest
|
||||||
|
WSResponse
|
||||||
|
*/
|
||||||
|
package echoserver
|
||||||
|
|
||||||
|
import proto "github.com/golang/protobuf/proto"
|
||||||
|
import fmt "fmt"
|
||||||
|
import math "math"
|
||||||
|
import _ "google.golang.org/genproto/googleapis/api/annotations"
|
||||||
|
|
||||||
|
import (
|
||||||
|
context "golang.org/x/net/context"
|
||||||
|
grpc "google.golang.org/grpc"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ = proto.Marshal
|
||||||
|
var _ = fmt.Errorf
|
||||||
|
var _ = math.Inf
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the proto package it is being compiled against.
|
||||||
|
// A compilation error at this line likely means your copy of the
|
||||||
|
// proto package needs to be updated.
|
||||||
|
const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package
|
||||||
|
|
||||||
|
type WSRequest struct {
|
||||||
|
MsgType string `protobuf:"bytes,1,opt,name=msgType" json:"msgType,omitempty"`
|
||||||
|
UserId string `protobuf:"bytes,2,opt,name=userId" json:"userId,omitempty"`
|
||||||
|
Msg string `protobuf:"bytes,3,opt,name=msg" json:"msg,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *WSRequest) Reset() { *m = WSRequest{} }
|
||||||
|
func (m *WSRequest) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*WSRequest) ProtoMessage() {}
|
||||||
|
func (*WSRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{0} }
|
||||||
|
|
||||||
|
func (m *WSRequest) GetMsgType() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.MsgType
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *WSRequest) GetUserId() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.UserId
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *WSRequest) GetMsg() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.Msg
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
type WSResponse struct {
|
||||||
|
MsgType string `protobuf:"bytes,1,opt,name=msgType" json:"msgType,omitempty"`
|
||||||
|
UserId string `protobuf:"bytes,2,opt,name=userId" json:"userId,omitempty"`
|
||||||
|
Msg string `protobuf:"bytes,3,opt,name=msg" json:"msg,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *WSResponse) Reset() { *m = WSResponse{} }
|
||||||
|
func (m *WSResponse) String() string { return proto.CompactTextString(m) }
|
||||||
|
func (*WSResponse) ProtoMessage() {}
|
||||||
|
func (*WSResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1} }
|
||||||
|
|
||||||
|
func (m *WSResponse) GetMsgType() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.MsgType
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *WSResponse) GetUserId() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.UserId
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *WSResponse) GetMsg() string {
|
||||||
|
if m != nil {
|
||||||
|
return m.Msg
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
proto.RegisterType((*WSRequest)(nil), "echoserver.WSRequest")
|
||||||
|
proto.RegisterType((*WSResponse)(nil), "echoserver.WSResponse")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
var _ context.Context
|
||||||
|
var _ grpc.ClientConn
|
||||||
|
|
||||||
|
// This is a compile-time assertion to ensure that this generated file
|
||||||
|
// is compatible with the grpc package it is being compiled against.
|
||||||
|
const _ = grpc.SupportPackageIsVersion4
|
||||||
|
|
||||||
|
// Client API for WebSocketService service
|
||||||
|
|
||||||
|
type WebSocketServiceClient interface {
|
||||||
|
Test(ctx context.Context, opts ...grpc.CallOption) (WebSocketService_TestClient, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type webSocketServiceClient struct {
|
||||||
|
cc *grpc.ClientConn
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWebSocketServiceClient(cc *grpc.ClientConn) WebSocketServiceClient {
|
||||||
|
return &webSocketServiceClient{cc}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *webSocketServiceClient) Test(ctx context.Context, opts ...grpc.CallOption) (WebSocketService_TestClient, error) {
|
||||||
|
stream, err := grpc.NewClientStream(ctx, &_WebSocketService_serviceDesc.Streams[0], c.cc, "/echoserver.WebSocketService/Test", opts...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
x := &webSocketServiceTestClient{stream}
|
||||||
|
return x, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebSocketService_TestClient interface {
|
||||||
|
Send(*WSRequest) error
|
||||||
|
Recv() (*WSResponse, error)
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type webSocketServiceTestClient struct {
|
||||||
|
grpc.ClientStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *webSocketServiceTestClient) Send(m *WSRequest) error {
|
||||||
|
return x.ClientStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *webSocketServiceTestClient) Recv() (*WSResponse, error) {
|
||||||
|
m := new(WSResponse)
|
||||||
|
if err := x.ClientStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server API for WebSocketService service
|
||||||
|
|
||||||
|
type WebSocketServiceServer interface {
|
||||||
|
Test(WebSocketService_TestServer) error
|
||||||
|
}
|
||||||
|
|
||||||
|
func RegisterWebSocketServiceServer(s *grpc.Server, srv WebSocketServiceServer) {
|
||||||
|
s.RegisterService(&_WebSocketService_serviceDesc, srv)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _WebSocketService_Test_Handler(srv interface{}, stream grpc.ServerStream) error {
|
||||||
|
return srv.(WebSocketServiceServer).Test(&webSocketServiceTestServer{stream})
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebSocketService_TestServer interface {
|
||||||
|
Send(*WSResponse) error
|
||||||
|
Recv() (*WSRequest, error)
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
type webSocketServiceTestServer struct {
|
||||||
|
grpc.ServerStream
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *webSocketServiceTestServer) Send(m *WSResponse) error {
|
||||||
|
return x.ServerStream.SendMsg(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *webSocketServiceTestServer) Recv() (*WSRequest, error) {
|
||||||
|
m := new(WSRequest)
|
||||||
|
if err := x.ServerStream.RecvMsg(m); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _WebSocketService_serviceDesc = grpc.ServiceDesc{
|
||||||
|
ServiceName: "echoserver.WebSocketService",
|
||||||
|
HandlerType: (*WebSocketServiceServer)(nil),
|
||||||
|
Methods: []grpc.MethodDesc{},
|
||||||
|
Streams: []grpc.StreamDesc{
|
||||||
|
{
|
||||||
|
StreamName: "Test",
|
||||||
|
Handler: _WebSocketService_Test_Handler,
|
||||||
|
ServerStreams: true,
|
||||||
|
ClientStreams: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Metadata: "ws/ws.proto",
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { proto.RegisterFile("ws/ws.proto", fileDescriptor0) }
|
||||||
|
|
||||||
|
var fileDescriptor0 = []byte{
|
||||||
|
// 214 bytes of a gzipped FileDescriptorProto
|
||||||
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x2e, 0x2f, 0xd6, 0x2f,
|
||||||
|
0x2f, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x4a, 0x4d, 0xce, 0xc8, 0x2f, 0x4e, 0x2d,
|
||||||
|
0x2a, 0x4b, 0x2d, 0x92, 0x92, 0x49, 0xcf, 0xcf, 0x4f, 0xcf, 0x49, 0xd5, 0x4f, 0x2c, 0xc8, 0xd4,
|
||||||
|
0x4f, 0xcc, 0xcb, 0xcb, 0x2f, 0x49, 0x2c, 0xc9, 0xcc, 0xcf, 0x83, 0xaa, 0x54, 0xf2, 0xe7, 0xe2,
|
||||||
|
0x0c, 0x0f, 0x0e, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, 0x2e, 0x11, 0x92, 0xe0, 0x62, 0xcf, 0x2d, 0x4e,
|
||||||
|
0x0f, 0xa9, 0x2c, 0x48, 0x95, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x0c, 0x82, 0x71, 0x85, 0xc4, 0xb8,
|
||||||
|
0xd8, 0x4a, 0x8b, 0x53, 0x8b, 0x3c, 0x53, 0x24, 0x98, 0xc0, 0x12, 0x50, 0x9e, 0x90, 0x00, 0x17,
|
||||||
|
0x73, 0x6e, 0x71, 0xba, 0x04, 0x33, 0x58, 0x10, 0xc4, 0x54, 0x0a, 0xe0, 0xe2, 0x02, 0x19, 0x58,
|
||||||
|
0x5c, 0x90, 0x9f, 0x57, 0x9c, 0x4a, 0x0d, 0x13, 0x8d, 0xa2, 0xb8, 0x04, 0xc2, 0x53, 0x93, 0x82,
|
||||||
|
0xf3, 0x93, 0xb3, 0x53, 0x4b, 0x82, 0x53, 0x8b, 0xca, 0x32, 0x93, 0x53, 0x85, 0xdc, 0xb8, 0x58,
|
||||||
|
0x42, 0x40, 0x2e, 0x16, 0xd5, 0x43, 0xf8, 0x54, 0x0f, 0xee, 0x11, 0x29, 0x31, 0x74, 0x61, 0x88,
|
||||||
|
0x73, 0x94, 0xb8, 0x9b, 0x2e, 0x3f, 0x99, 0xcc, 0xc4, 0x2a, 0xc4, 0xac, 0x5f, 0x5e, 0xac, 0xc1,
|
||||||
|
0x68, 0xc0, 0x98, 0xc4, 0x06, 0x0e, 0x05, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, 0xff, 0x2a, 0x14,
|
||||||
|
0xdd, 0x6e, 0x3e, 0x01, 0x00, 0x00,
|
||||||
|
}
|
152
ws/ws.pb.gw.go
Normal file
152
ws/ws.pb.gw.go
Normal file
|
@ -0,0 +1,152 @@
|
||||||
|
// Code generated by protoc-gen-grpc-gateway
|
||||||
|
// source: ws/ws.proto
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
|
/*
|
||||||
|
Package echoserver is a reverse proxy.
|
||||||
|
|
||||||
|
It translates gRPC into RESTful JSON APIs.
|
||||||
|
*/
|
||||||
|
package echoserver
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
|
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||||
|
"github.com/grpc-ecosystem/grpc-gateway/utilities"
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/grpclog"
|
||||||
|
"google.golang.org/grpc/status"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ codes.Code
|
||||||
|
var _ io.Reader
|
||||||
|
var _ status.Status
|
||||||
|
var _ = runtime.String
|
||||||
|
var _ = utilities.NewDoubleArray
|
||||||
|
|
||||||
|
func request_WebSocketService_Test_0(ctx context.Context, marshaler runtime.Marshaler, client WebSocketServiceClient, req *http.Request, pathParams map[string]string) (WebSocketService_TestClient, runtime.ServerMetadata, error) {
|
||||||
|
var metadata runtime.ServerMetadata
|
||||||
|
stream, err := client.Test(ctx)
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Printf("Failed to start streaming: %v", err)
|
||||||
|
return nil, metadata, err
|
||||||
|
}
|
||||||
|
dec := marshaler.NewDecoder(req.Body)
|
||||||
|
handleSend := func() error {
|
||||||
|
var protoReq WSRequest
|
||||||
|
err = dec.Decode(&protoReq)
|
||||||
|
if err == io.EOF {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Printf("Failed to decode request: %v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err = stream.Send(&protoReq); err != nil {
|
||||||
|
grpclog.Printf("Failed to send request: %v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err := handleSend(); err != nil {
|
||||||
|
if cerr := stream.CloseSend(); cerr != nil {
|
||||||
|
grpclog.Printf("Failed to terminate client stream: %v", cerr)
|
||||||
|
}
|
||||||
|
if err == io.EOF {
|
||||||
|
return stream, metadata, nil
|
||||||
|
}
|
||||||
|
return nil, metadata, err
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
if err := handleSend(); err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := stream.CloseSend(); err != nil {
|
||||||
|
grpclog.Printf("Failed to terminate client stream: %v", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
header, err := stream.Header()
|
||||||
|
if err != nil {
|
||||||
|
grpclog.Printf("Failed to get header from client: %v", err)
|
||||||
|
return nil, metadata, err
|
||||||
|
}
|
||||||
|
metadata.HeaderMD = header
|
||||||
|
return stream, metadata, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterWebSocketServiceHandlerFromEndpoint is same as RegisterWebSocketServiceHandler but
|
||||||
|
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
|
||||||
|
func RegisterWebSocketServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
|
||||||
|
conn, err := grpc.Dial(endpoint, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
if cerr := conn.Close(); cerr != nil {
|
||||||
|
grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
<-ctx.Done()
|
||||||
|
if cerr := conn.Close(); cerr != nil {
|
||||||
|
grpclog.Printf("Failed to close conn to %s: %v", endpoint, cerr)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}()
|
||||||
|
|
||||||
|
return RegisterWebSocketServiceHandler(ctx, mux, conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RegisterWebSocketServiceHandler registers the http handlers for service WebSocketService to "mux".
|
||||||
|
// The handlers forward requests to the grpc endpoint over "conn".
|
||||||
|
func RegisterWebSocketServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
|
||||||
|
client := NewWebSocketServiceClient(conn)
|
||||||
|
|
||||||
|
mux.Handle("GET", pattern_WebSocketService_Test_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
|
||||||
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
|
defer cancel()
|
||||||
|
if cn, ok := w.(http.CloseNotifier); ok {
|
||||||
|
go func(done <-chan struct{}, closed <-chan bool) {
|
||||||
|
select {
|
||||||
|
case <-done:
|
||||||
|
case <-closed:
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
|
}(ctx.Done(), cn.CloseNotify())
|
||||||
|
}
|
||||||
|
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
|
||||||
|
rctx, err := runtime.AnnotateContext(ctx, mux, req)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resp, md, err := request_WebSocketService_Test_0(rctx, inboundMarshaler, client, req, pathParams)
|
||||||
|
ctx = runtime.NewServerMetadataContext(ctx, md)
|
||||||
|
if err != nil {
|
||||||
|
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
forward_WebSocketService_Test_0(ctx, mux, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
pattern_WebSocketService_Test_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"ws"}, ""))
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
forward_WebSocketService_Test_0 = runtime.ForwardResponseStream
|
||||||
|
)
|
Loading…
Reference in New Issue
Block a user