diff --git a/examples/examplepb/a_bit_of_everything.pb.go b/examples/examplepb/a_bit_of_everything.pb.go index 18b174ac92f..21b8e96c92c 100644 --- a/examples/examplepb/a_bit_of_everything.pb.go +++ b/examples/examplepb/a_bit_of_everything.pb.go @@ -132,7 +132,7 @@ 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.SupportPackageIsVersion1 +const _ = grpc.SupportPackageIsVersion2 // Client API for ABitOfEverythingService service @@ -325,28 +325,40 @@ func RegisterABitOfEverythingServiceServer(s *grpc.Server, srv ABitOfEverythingS s.RegisterService(&_ABitOfEverythingService_serviceDesc, srv) } -func _ABitOfEverythingService_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _ABitOfEverythingService_Create_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(ABitOfEverything) if err := dec(in); err != nil { return nil, err } - out, err := srv.(ABitOfEverythingServiceServer).Create(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(ABitOfEverythingServiceServer).Create(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/Create", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ABitOfEverythingServiceServer).Create(ctx, req.(*ABitOfEverything)) + } + return interceptor(ctx, in, info, handler) } -func _ABitOfEverythingService_CreateBody_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _ABitOfEverythingService_CreateBody_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(ABitOfEverything) if err := dec(in); err != nil { return nil, err } - out, err := srv.(ABitOfEverythingServiceServer).CreateBody(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(ABitOfEverythingServiceServer).CreateBody(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/CreateBody", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ABitOfEverythingServiceServer).CreateBody(ctx, req.(*ABitOfEverything)) + } + return interceptor(ctx, in, info, handler) } func _ABitOfEverythingService_BulkCreate_Handler(srv interface{}, stream grpc.ServerStream) error { @@ -375,16 +387,22 @@ func (x *aBitOfEverythingServiceBulkCreateServer) Recv() (*ABitOfEverything, err return m, nil } -func _ABitOfEverythingService_Lookup_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _ABitOfEverythingService_Lookup_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(sub2.IdMessage) if err := dec(in); err != nil { return nil, err } - out, err := srv.(ABitOfEverythingServiceServer).Lookup(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(ABitOfEverythingServiceServer).Lookup(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/Lookup", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ABitOfEverythingServiceServer).Lookup(ctx, req.(*sub2.IdMessage)) + } + return interceptor(ctx, in, info, handler) } func _ABitOfEverythingService_List_Handler(srv interface{}, stream grpc.ServerStream) error { @@ -408,40 +426,58 @@ func (x *aBitOfEverythingServiceListServer) Send(m *ABitOfEverything) error { return x.ServerStream.SendMsg(m) } -func _ABitOfEverythingService_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _ABitOfEverythingService_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(ABitOfEverything) if err := dec(in); err != nil { return nil, err } - out, err := srv.(ABitOfEverythingServiceServer).Update(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(ABitOfEverythingServiceServer).Update(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/Update", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ABitOfEverythingServiceServer).Update(ctx, req.(*ABitOfEverything)) + } + return interceptor(ctx, in, info, handler) } -func _ABitOfEverythingService_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _ABitOfEverythingService_Delete_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(sub2.IdMessage) if err := dec(in); err != nil { return nil, err } - out, err := srv.(ABitOfEverythingServiceServer).Delete(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(ABitOfEverythingServiceServer).Delete(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/Delete", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ABitOfEverythingServiceServer).Delete(ctx, req.(*sub2.IdMessage)) + } + return interceptor(ctx, in, info, handler) } -func _ABitOfEverythingService_Echo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _ABitOfEverythingService_Echo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(gengo_grpc_gateway_examples_sub.StringMessage) if err := dec(in); err != nil { return nil, err } - out, err := srv.(ABitOfEverythingServiceServer).Echo(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(ABitOfEverythingServiceServer).Echo(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.ABitOfEverythingService/Echo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ABitOfEverythingServiceServer).Echo(ctx, req.(*gengo_grpc_gateway_examples_sub.StringMessage)) + } + return interceptor(ctx, in, info, handler) } func _ABitOfEverythingService_BulkEcho_Handler(srv interface{}, stream grpc.ServerStream) error { diff --git a/examples/examplepb/a_bit_of_everything.pb.gw.go b/examples/examplepb/a_bit_of_everything.pb.gw.go index f6f214bfb5d..5c07e4c0782 100644 --- a/examples/examplepb/a_bit_of_everything.pb.gw.go +++ b/examples/examplepb/a_bit_of_everything.pb.gw.go @@ -10,7 +10,6 @@ It translates gRPC into RESTful JSON APIs. package examplepb import ( - "encoding/json" "io" "net/http" @@ -28,14 +27,13 @@ import ( var _ codes.Code var _ io.Reader var _ = runtime.String -var _ = json.Marshal var _ = utilities.NewDoubleArray var ( filter_ABitOfEverythingService_Create_0 = &utilities.DoubleArray{Encoding: map[string]int{"float_value": 0, "double_value": 1, "int64_value": 2, "uint64_value": 3, "int32_value": 4, "fixed64_value": 5, "fixed32_value": 6, "bool_value": 7, "string_value": 8, "uint32_value": 9, "sfixed32_value": 10, "sfixed64_value": 11, "sint32_value": 12, "sint64_value": 13}, Base: []int{1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, Check: []int{0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}} ) -func request_ABitOfEverythingService_Create_0(ctx context.Context, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_ABitOfEverythingService_Create_0(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq ABitOfEverything var metadata runtime.ServerMetadata @@ -209,11 +207,11 @@ func request_ABitOfEverythingService_Create_0(ctx context.Context, client ABitOf } -func request_ABitOfEverythingService_CreateBody_0(ctx context.Context, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_ABitOfEverythingService_CreateBody_0(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq ABitOfEverything var metadata runtime.ServerMetadata - if err := json.NewDecoder(req.Body).Decode(&protoReq); err != nil { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) } @@ -222,14 +220,14 @@ func request_ABitOfEverythingService_CreateBody_0(ctx context.Context, client AB } -func request_ABitOfEverythingService_BulkCreate_0(ctx context.Context, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_ABitOfEverythingService_BulkCreate_0(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var metadata runtime.ServerMetadata stream, err := client.BulkCreate(ctx) if err != nil { grpclog.Printf("Failed to start streaming: %v", err) return nil, metadata, err } - dec := json.NewDecoder(req.Body) + dec := marshaler.NewDecoder(req.Body) for { var protoReq ABitOfEverything err = dec.Decode(&protoReq) @@ -263,7 +261,7 @@ func request_ABitOfEverythingService_BulkCreate_0(ctx context.Context, client AB } -func request_ABitOfEverythingService_Lookup_0(ctx context.Context, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_ABitOfEverythingService_Lookup_0(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq sub2.IdMessage var metadata runtime.ServerMetadata @@ -290,7 +288,7 @@ func request_ABitOfEverythingService_Lookup_0(ctx context.Context, client ABitOf } -func request_ABitOfEverythingService_List_0(ctx context.Context, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (ABitOfEverythingService_ListClient, runtime.ServerMetadata, error) { +func request_ABitOfEverythingService_List_0(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (ABitOfEverythingService_ListClient, runtime.ServerMetadata, error) { var protoReq EmptyMessage var metadata runtime.ServerMetadata @@ -307,11 +305,11 @@ func request_ABitOfEverythingService_List_0(ctx context.Context, client ABitOfEv } -func request_ABitOfEverythingService_Update_0(ctx context.Context, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_ABitOfEverythingService_Update_0(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq ABitOfEverything var metadata runtime.ServerMetadata - if err := json.NewDecoder(req.Body).Decode(&protoReq); err != nil { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) } @@ -338,7 +336,7 @@ func request_ABitOfEverythingService_Update_0(ctx context.Context, client ABitOf } -func request_ABitOfEverythingService_Delete_0(ctx context.Context, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_ABitOfEverythingService_Delete_0(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq sub2.IdMessage var metadata runtime.ServerMetadata @@ -365,7 +363,7 @@ func request_ABitOfEverythingService_Delete_0(ctx context.Context, client ABitOf } -func request_ABitOfEverythingService_Echo_0(ctx context.Context, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_ABitOfEverythingService_Echo_0(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq sub.StringMessage var metadata runtime.ServerMetadata @@ -392,11 +390,11 @@ func request_ABitOfEverythingService_Echo_0(ctx context.Context, client ABitOfEv } -func request_ABitOfEverythingService_Echo_1(ctx context.Context, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_ABitOfEverythingService_Echo_1(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq sub.StringMessage var metadata runtime.ServerMetadata - if err := json.NewDecoder(req.Body).Decode(&protoReq.Value); err != nil { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.Value); err != nil { return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) } @@ -409,7 +407,7 @@ var ( filter_ABitOfEverythingService_Echo_2 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} ) -func request_ABitOfEverythingService_Echo_2(ctx context.Context, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_ABitOfEverythingService_Echo_2(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq sub.StringMessage var metadata runtime.ServerMetadata @@ -422,14 +420,14 @@ func request_ABitOfEverythingService_Echo_2(ctx context.Context, client ABitOfEv } -func request_ABitOfEverythingService_BulkEcho_0(ctx context.Context, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (ABitOfEverythingService_BulkEchoClient, runtime.ServerMetadata, error) { +func request_ABitOfEverythingService_BulkEcho_0(ctx context.Context, marshaler runtime.Marshaler, client ABitOfEverythingServiceClient, req *http.Request, pathParams map[string]string) (ABitOfEverythingService_BulkEchoClient, runtime.ServerMetadata, error) { var metadata runtime.ServerMetadata stream, err := client.BulkEcho(ctx) if err != nil { grpclog.Printf("Failed to start streaming: %v", err) return nil, metadata, err } - dec := json.NewDecoder(req.Body) + dec := marshaler.NewDecoder(req.Body) for { var protoReq sub.StringMessage err = dec.Decode(&protoReq) @@ -503,14 +501,15 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_ABitOfEverythingService_Create_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_ABitOfEverythingService_Create_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_ABitOfEverythingService_Create_0(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_ABitOfEverythingService_Create_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -526,14 +525,15 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_ABitOfEverythingService_CreateBody_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_ABitOfEverythingService_CreateBody_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_ABitOfEverythingService_CreateBody_0(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_ABitOfEverythingService_CreateBody_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -549,14 +549,15 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_ABitOfEverythingService_BulkCreate_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_ABitOfEverythingService_BulkCreate_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_ABitOfEverythingService_BulkCreate_0(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_ABitOfEverythingService_BulkCreate_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -572,14 +573,15 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_ABitOfEverythingService_Lookup_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_ABitOfEverythingService_Lookup_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_ABitOfEverythingService_Lookup_0(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_ABitOfEverythingService_Lookup_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -595,14 +597,15 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_ABitOfEverythingService_List_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_ABitOfEverythingService_List_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_ABitOfEverythingService_List_0(ctx, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) + forward_ABitOfEverythingService_List_0(ctx, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) }) @@ -618,14 +621,15 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_ABitOfEverythingService_Update_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_ABitOfEverythingService_Update_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_ABitOfEverythingService_Update_0(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_ABitOfEverythingService_Update_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -641,14 +645,15 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_ABitOfEverythingService_Delete_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_ABitOfEverythingService_Delete_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_ABitOfEverythingService_Delete_0(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_ABitOfEverythingService_Delete_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -664,14 +669,15 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_ABitOfEverythingService_Echo_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_ABitOfEverythingService_Echo_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_ABitOfEverythingService_Echo_0(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_ABitOfEverythingService_Echo_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -687,14 +693,15 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_ABitOfEverythingService_Echo_1(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_ABitOfEverythingService_Echo_1(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_ABitOfEverythingService_Echo_1(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_ABitOfEverythingService_Echo_1(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -710,14 +717,15 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_ABitOfEverythingService_Echo_2(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_ABitOfEverythingService_Echo_2(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_ABitOfEverythingService_Echo_2(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_ABitOfEverythingService_Echo_2(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -733,14 +741,15 @@ func RegisterABitOfEverythingServiceHandler(ctx context.Context, mux *runtime.Se } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_ABitOfEverythingService_BulkEcho_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_ABitOfEverythingService_BulkEcho_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_ABitOfEverythingService_BulkEcho_0(ctx, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) + forward_ABitOfEverythingService_BulkEcho_0(ctx, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) }) diff --git a/examples/examplepb/echo_service.pb.go b/examples/examplepb/echo_service.pb.go index 76cd1d1250c..4c78cacd2b6 100644 --- a/examples/examplepb/echo_service.pb.go +++ b/examples/examplepb/echo_service.pb.go @@ -60,7 +60,7 @@ 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.SupportPackageIsVersion1 +const _ = grpc.SupportPackageIsVersion2 // Client API for EchoService service @@ -106,28 +106,40 @@ func RegisterEchoServiceServer(s *grpc.Server, srv EchoServiceServer) { s.RegisterService(&_EchoService_serviceDesc, srv) } -func _EchoService_Echo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _EchoService_Echo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(SimpleMessage) if err := dec(in); err != nil { return nil, err } - out, err := srv.(EchoServiceServer).Echo(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(EchoServiceServer).Echo(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.EchoService/Echo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(EchoServiceServer).Echo(ctx, req.(*SimpleMessage)) + } + return interceptor(ctx, in, info, handler) } -func _EchoService_EchoBody_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _EchoService_EchoBody_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(SimpleMessage) if err := dec(in); err != nil { return nil, err } - out, err := srv.(EchoServiceServer).EchoBody(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(EchoServiceServer).EchoBody(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.EchoService/EchoBody", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(EchoServiceServer).EchoBody(ctx, req.(*SimpleMessage)) + } + return interceptor(ctx, in, info, handler) } var _EchoService_serviceDesc = grpc.ServiceDesc{ diff --git a/examples/examplepb/echo_service.pb.gw.go b/examples/examplepb/echo_service.pb.gw.go index 6ab992ad9f8..6cb8c55cc3c 100644 --- a/examples/examplepb/echo_service.pb.gw.go +++ b/examples/examplepb/echo_service.pb.gw.go @@ -10,7 +10,6 @@ It translates gRPC into RESTful JSON APIs. package examplepb import ( - "encoding/json" "io" "net/http" @@ -26,10 +25,9 @@ import ( var _ codes.Code var _ io.Reader var _ = runtime.String -var _ = json.Marshal var _ = utilities.NewDoubleArray -func request_EchoService_Echo_0(ctx context.Context, client EchoServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_EchoService_Echo_0(ctx context.Context, marshaler runtime.Marshaler, client EchoServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq SimpleMessage var metadata runtime.ServerMetadata @@ -56,11 +54,11 @@ func request_EchoService_Echo_0(ctx context.Context, client EchoServiceClient, r } -func request_EchoService_EchoBody_0(ctx context.Context, client EchoServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_EchoService_EchoBody_0(ctx context.Context, marshaler runtime.Marshaler, client EchoServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq SimpleMessage var metadata runtime.ServerMetadata - if err := json.NewDecoder(req.Body).Decode(&protoReq); err != nil { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) } @@ -111,14 +109,15 @@ func RegisterEchoServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_EchoService_Echo_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_EchoService_Echo_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_EchoService_Echo_0(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_EchoService_Echo_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -134,14 +133,15 @@ func RegisterEchoServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_EchoService_EchoBody_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_EchoService_EchoBody_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_EchoService_EchoBody_0(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_EchoService_EchoBody_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) diff --git a/examples/examplepb/flow_combination.pb.go b/examples/examplepb/flow_combination.pb.go index 40606b6eb0d..345f7ed5a8a 100644 --- a/examples/examplepb/flow_combination.pb.go +++ b/examples/examplepb/flow_combination.pb.go @@ -95,7 +95,7 @@ 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.SupportPackageIsVersion1 +const _ = grpc.SupportPackageIsVersion2 // Client API for FlowCombination service @@ -368,16 +368,22 @@ func RegisterFlowCombinationServer(s *grpc.Server, srv FlowCombinationServer) { s.RegisterService(&_FlowCombination_serviceDesc, srv) } -func _FlowCombination_RpcEmptyRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _FlowCombination_RpcEmptyRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(EmptyProto) if err := dec(in); err != nil { return nil, err } - out, err := srv.(FlowCombinationServer).RpcEmptyRpc(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(FlowCombinationServer).RpcEmptyRpc(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.FlowCombination/RpcEmptyRpc", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(FlowCombinationServer).RpcEmptyRpc(ctx, req.(*EmptyProto)) + } + return interceptor(ctx, in, info, handler) } func _FlowCombination_RpcEmptyStream_Handler(srv interface{}, stream grpc.ServerStream) error { @@ -453,40 +459,58 @@ func (x *flowCombinationStreamEmptyStreamServer) Recv() (*EmptyProto, error) { return m, nil } -func _FlowCombination_RpcBodyRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _FlowCombination_RpcBodyRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(NonEmptyProto) if err := dec(in); err != nil { return nil, err } - out, err := srv.(FlowCombinationServer).RpcBodyRpc(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(FlowCombinationServer).RpcBodyRpc(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.FlowCombination/RpcBodyRpc", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(FlowCombinationServer).RpcBodyRpc(ctx, req.(*NonEmptyProto)) + } + return interceptor(ctx, in, info, handler) } -func _FlowCombination_RpcPathSingleNestedRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _FlowCombination_RpcPathSingleNestedRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(SingleNestedProto) if err := dec(in); err != nil { return nil, err } - out, err := srv.(FlowCombinationServer).RpcPathSingleNestedRpc(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(FlowCombinationServer).RpcPathSingleNestedRpc(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.FlowCombination/RpcPathSingleNestedRpc", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(FlowCombinationServer).RpcPathSingleNestedRpc(ctx, req.(*SingleNestedProto)) + } + return interceptor(ctx, in, info, handler) } -func _FlowCombination_RpcPathNestedRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error) (interface{}, error) { +func _FlowCombination_RpcPathNestedRpc_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(NestedProto) if err := dec(in); err != nil { return nil, err } - out, err := srv.(FlowCombinationServer).RpcPathNestedRpc(ctx, in) - if err != nil { - return nil, err + if interceptor == nil { + return srv.(FlowCombinationServer).RpcPathNestedRpc(ctx, in) } - return out, nil + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/gengo.grpc.gateway.examples.examplepb.FlowCombination/RpcPathNestedRpc", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(FlowCombinationServer).RpcPathNestedRpc(ctx, req.(*NestedProto)) + } + return interceptor(ctx, in, info, handler) } func _FlowCombination_RpcBodyStream_Handler(srv interface{}, stream grpc.ServerStream) error { diff --git a/examples/examplepb/flow_combination.pb.gw.go b/examples/examplepb/flow_combination.pb.gw.go index 6230e23a50d..8b575104f05 100644 --- a/examples/examplepb/flow_combination.pb.gw.go +++ b/examples/examplepb/flow_combination.pb.gw.go @@ -10,7 +10,6 @@ It translates gRPC into RESTful JSON APIs. package examplepb import ( - "encoding/json" "io" "net/http" @@ -26,10 +25,9 @@ import ( var _ codes.Code var _ io.Reader var _ = runtime.String -var _ = json.Marshal var _ = utilities.NewDoubleArray -func request_FlowCombination_RpcEmptyRpc_0(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcEmptyRpc_0(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq EmptyProto var metadata runtime.ServerMetadata @@ -38,7 +36,7 @@ func request_FlowCombination_RpcEmptyRpc_0(ctx context.Context, client FlowCombi } -func request_FlowCombination_RpcEmptyStream_0(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcEmptyStreamClient, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcEmptyStream_0(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcEmptyStreamClient, runtime.ServerMetadata, error) { var protoReq EmptyProto var metadata runtime.ServerMetadata @@ -55,14 +53,14 @@ func request_FlowCombination_RpcEmptyStream_0(ctx context.Context, client FlowCo } -func request_FlowCombination_StreamEmptyRpc_0(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_FlowCombination_StreamEmptyRpc_0(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var metadata runtime.ServerMetadata stream, err := client.StreamEmptyRpc(ctx) if err != nil { grpclog.Printf("Failed to start streaming: %v", err) return nil, metadata, err } - dec := json.NewDecoder(req.Body) + dec := marshaler.NewDecoder(req.Body) for { var protoReq EmptyProto err = dec.Decode(&protoReq) @@ -96,14 +94,14 @@ func request_FlowCombination_StreamEmptyRpc_0(ctx context.Context, client FlowCo } -func request_FlowCombination_StreamEmptyStream_0(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_StreamEmptyStreamClient, runtime.ServerMetadata, error) { +func request_FlowCombination_StreamEmptyStream_0(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_StreamEmptyStreamClient, runtime.ServerMetadata, error) { var metadata runtime.ServerMetadata stream, err := client.StreamEmptyStream(ctx) if err != nil { grpclog.Printf("Failed to start streaming: %v", err) return nil, metadata, err } - dec := json.NewDecoder(req.Body) + dec := marshaler.NewDecoder(req.Body) for { var protoReq EmptyProto err = dec.Decode(&protoReq) @@ -135,11 +133,11 @@ func request_FlowCombination_StreamEmptyStream_0(ctx context.Context, client Flo } -func request_FlowCombination_RpcBodyRpc_0(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcBodyRpc_0(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq NonEmptyProto var metadata runtime.ServerMetadata - if err := json.NewDecoder(req.Body).Decode(&protoReq); err != nil { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) } @@ -148,7 +146,7 @@ func request_FlowCombination_RpcBodyRpc_0(ctx context.Context, client FlowCombin } -func request_FlowCombination_RpcBodyRpc_1(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcBodyRpc_1(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq NonEmptyProto var metadata runtime.ServerMetadata @@ -201,7 +199,7 @@ var ( filter_FlowCombination_RpcBodyRpc_2 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} ) -func request_FlowCombination_RpcBodyRpc_2(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcBodyRpc_2(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq NonEmptyProto var metadata runtime.ServerMetadata @@ -214,11 +212,11 @@ func request_FlowCombination_RpcBodyRpc_2(ctx context.Context, client FlowCombin } -func request_FlowCombination_RpcBodyRpc_3(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcBodyRpc_3(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq NonEmptyProto var metadata runtime.ServerMetadata - if err := json.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) } @@ -260,11 +258,11 @@ var ( filter_FlowCombination_RpcBodyRpc_4 = &utilities.DoubleArray{Encoding: map[string]int{"c": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} ) -func request_FlowCombination_RpcBodyRpc_4(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcBodyRpc_4(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq NonEmptyProto var metadata runtime.ServerMetadata - if err := json.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) } @@ -281,11 +279,11 @@ var ( filter_FlowCombination_RpcBodyRpc_5 = &utilities.DoubleArray{Encoding: map[string]int{"c": 0, "a": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}} ) -func request_FlowCombination_RpcBodyRpc_5(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcBodyRpc_5(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq NonEmptyProto var metadata runtime.ServerMetadata - if err := json.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) } @@ -320,7 +318,7 @@ var ( filter_FlowCombination_RpcBodyRpc_6 = &utilities.DoubleArray{Encoding: map[string]int{"a": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} ) -func request_FlowCombination_RpcBodyRpc_6(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcBodyRpc_6(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq NonEmptyProto var metadata runtime.ServerMetadata @@ -355,7 +353,7 @@ var ( filter_FlowCombination_RpcPathSingleNestedRpc_0 = &utilities.DoubleArray{Encoding: map[string]int{"a": 0, "str": 1}, Base: []int{1, 1, 1, 0}, Check: []int{0, 1, 2, 3}} ) -func request_FlowCombination_RpcPathSingleNestedRpc_0(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcPathSingleNestedRpc_0(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq SingleNestedProto var metadata runtime.ServerMetadata @@ -390,11 +388,11 @@ var ( filter_FlowCombination_RpcPathNestedRpc_0 = &utilities.DoubleArray{Encoding: map[string]int{"c": 0, "a": 1, "str": 2, "b": 3}, Base: []int{1, 1, 1, 2, 3, 0, 0, 0}, Check: []int{0, 1, 1, 3, 1, 2, 4, 5}} ) -func request_FlowCombination_RpcPathNestedRpc_0(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcPathNestedRpc_0(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq NestedProto var metadata runtime.ServerMetadata - if err := json.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) } @@ -440,7 +438,7 @@ var ( filter_FlowCombination_RpcPathNestedRpc_1 = &utilities.DoubleArray{Encoding: map[string]int{"a": 0, "str": 1}, Base: []int{1, 1, 1, 0}, Check: []int{0, 1, 2, 3}} ) -func request_FlowCombination_RpcPathNestedRpc_1(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcPathNestedRpc_1(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq NestedProto var metadata runtime.ServerMetadata @@ -475,11 +473,11 @@ var ( filter_FlowCombination_RpcPathNestedRpc_2 = &utilities.DoubleArray{Encoding: map[string]int{"c": 0, "a": 1, "str": 2}, Base: []int{1, 1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 3, 2, 4}} ) -func request_FlowCombination_RpcPathNestedRpc_2(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcPathNestedRpc_2(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq NestedProto var metadata runtime.ServerMetadata - if err := json.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) } @@ -510,11 +508,11 @@ func request_FlowCombination_RpcPathNestedRpc_2(ctx context.Context, client Flow } -func request_FlowCombination_RpcBodyStream_0(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcBodyStreamClient, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcBodyStream_0(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcBodyStreamClient, runtime.ServerMetadata, error) { var protoReq NonEmptyProto var metadata runtime.ServerMetadata - if err := json.NewDecoder(req.Body).Decode(&protoReq); err != nil { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil { return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) } @@ -531,7 +529,7 @@ func request_FlowCombination_RpcBodyStream_0(ctx context.Context, client FlowCom } -func request_FlowCombination_RpcBodyStream_1(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcBodyStreamClient, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcBodyStream_1(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcBodyStreamClient, runtime.ServerMetadata, error) { var protoReq NonEmptyProto var metadata runtime.ServerMetadata @@ -592,7 +590,7 @@ var ( filter_FlowCombination_RpcBodyStream_2 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} ) -func request_FlowCombination_RpcBodyStream_2(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcBodyStreamClient, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcBodyStream_2(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcBodyStreamClient, runtime.ServerMetadata, error) { var protoReq NonEmptyProto var metadata runtime.ServerMetadata @@ -613,11 +611,11 @@ func request_FlowCombination_RpcBodyStream_2(ctx context.Context, client FlowCom } -func request_FlowCombination_RpcBodyStream_3(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcBodyStreamClient, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcBodyStream_3(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcBodyStreamClient, runtime.ServerMetadata, error) { var protoReq NonEmptyProto var metadata runtime.ServerMetadata - if err := json.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) } @@ -667,11 +665,11 @@ var ( filter_FlowCombination_RpcBodyStream_4 = &utilities.DoubleArray{Encoding: map[string]int{"c": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} ) -func request_FlowCombination_RpcBodyStream_4(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcBodyStreamClient, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcBodyStream_4(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcBodyStreamClient, runtime.ServerMetadata, error) { var protoReq NonEmptyProto var metadata runtime.ServerMetadata - if err := json.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) } @@ -696,11 +694,11 @@ var ( filter_FlowCombination_RpcBodyStream_5 = &utilities.DoubleArray{Encoding: map[string]int{"c": 0, "a": 1}, Base: []int{1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 2, 3}} ) -func request_FlowCombination_RpcBodyStream_5(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcBodyStreamClient, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcBodyStream_5(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcBodyStreamClient, runtime.ServerMetadata, error) { var protoReq NonEmptyProto var metadata runtime.ServerMetadata - if err := json.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) } @@ -743,7 +741,7 @@ var ( filter_FlowCombination_RpcBodyStream_6 = &utilities.DoubleArray{Encoding: map[string]int{"a": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}} ) -func request_FlowCombination_RpcBodyStream_6(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcBodyStreamClient, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcBodyStream_6(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcBodyStreamClient, runtime.ServerMetadata, error) { var protoReq NonEmptyProto var metadata runtime.ServerMetadata @@ -786,7 +784,7 @@ var ( filter_FlowCombination_RpcPathSingleNestedStream_0 = &utilities.DoubleArray{Encoding: map[string]int{"a": 0, "str": 1}, Base: []int{1, 1, 1, 0}, Check: []int{0, 1, 2, 3}} ) -func request_FlowCombination_RpcPathSingleNestedStream_0(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcPathSingleNestedStreamClient, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcPathSingleNestedStream_0(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcPathSingleNestedStreamClient, runtime.ServerMetadata, error) { var protoReq SingleNestedProto var metadata runtime.ServerMetadata @@ -829,11 +827,11 @@ var ( filter_FlowCombination_RpcPathNestedStream_0 = &utilities.DoubleArray{Encoding: map[string]int{"c": 0, "a": 1, "str": 2, "b": 3}, Base: []int{1, 1, 1, 2, 3, 0, 0, 0}, Check: []int{0, 1, 1, 3, 1, 2, 4, 5}} ) -func request_FlowCombination_RpcPathNestedStream_0(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcPathNestedStreamClient, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcPathNestedStream_0(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcPathNestedStreamClient, runtime.ServerMetadata, error) { var protoReq NestedProto var metadata runtime.ServerMetadata - if err := json.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) } @@ -887,7 +885,7 @@ var ( filter_FlowCombination_RpcPathNestedStream_1 = &utilities.DoubleArray{Encoding: map[string]int{"a": 0, "str": 1}, Base: []int{1, 1, 1, 0}, Check: []int{0, 1, 2, 3}} ) -func request_FlowCombination_RpcPathNestedStream_1(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcPathNestedStreamClient, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcPathNestedStream_1(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcPathNestedStreamClient, runtime.ServerMetadata, error) { var protoReq NestedProto var metadata runtime.ServerMetadata @@ -930,11 +928,11 @@ var ( filter_FlowCombination_RpcPathNestedStream_2 = &utilities.DoubleArray{Encoding: map[string]int{"c": 0, "a": 1, "str": 2}, Base: []int{1, 1, 1, 2, 0, 0}, Check: []int{0, 1, 1, 3, 2, 4}} ) -func request_FlowCombination_RpcPathNestedStream_2(ctx context.Context, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcPathNestedStreamClient, runtime.ServerMetadata, error) { +func request_FlowCombination_RpcPathNestedStream_2(ctx context.Context, marshaler runtime.Marshaler, client FlowCombinationClient, req *http.Request, pathParams map[string]string) (FlowCombination_RpcPathNestedStreamClient, runtime.ServerMetadata, error) { var protoReq NestedProto var metadata runtime.ServerMetadata - if err := json.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.C); err != nil { return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) } @@ -1015,14 +1013,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcEmptyRpc_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcEmptyRpc_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcEmptyRpc_0(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcEmptyRpc_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1038,14 +1037,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcEmptyStream_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcEmptyStream_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcEmptyStream_0(ctx, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcEmptyStream_0(ctx, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) }) @@ -1061,14 +1061,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_StreamEmptyRpc_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_StreamEmptyRpc_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_StreamEmptyRpc_0(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_FlowCombination_StreamEmptyRpc_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1084,14 +1085,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_StreamEmptyStream_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_StreamEmptyStream_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_StreamEmptyStream_0(ctx, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) + forward_FlowCombination_StreamEmptyStream_0(ctx, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) }) @@ -1107,14 +1109,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcBodyRpc_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcBodyRpc_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcBodyRpc_0(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcBodyRpc_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1130,14 +1133,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcBodyRpc_1(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcBodyRpc_1(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcBodyRpc_1(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcBodyRpc_1(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1153,14 +1157,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcBodyRpc_2(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcBodyRpc_2(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcBodyRpc_2(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcBodyRpc_2(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1176,14 +1181,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcBodyRpc_3(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcBodyRpc_3(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcBodyRpc_3(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcBodyRpc_3(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1199,14 +1205,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcBodyRpc_4(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcBodyRpc_4(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcBodyRpc_4(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcBodyRpc_4(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1222,14 +1229,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcBodyRpc_5(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcBodyRpc_5(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcBodyRpc_5(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcBodyRpc_5(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1245,14 +1253,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcBodyRpc_6(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcBodyRpc_6(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcBodyRpc_6(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcBodyRpc_6(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1268,14 +1277,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcPathSingleNestedRpc_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcPathSingleNestedRpc_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcPathSingleNestedRpc_0(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcPathSingleNestedRpc_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1291,14 +1301,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcPathNestedRpc_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcPathNestedRpc_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcPathNestedRpc_0(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcPathNestedRpc_0(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1314,14 +1325,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcPathNestedRpc_1(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcPathNestedRpc_1(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcPathNestedRpc_1(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcPathNestedRpc_1(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1337,14 +1349,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcPathNestedRpc_2(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcPathNestedRpc_2(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcPathNestedRpc_2(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcPathNestedRpc_2(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -1360,14 +1373,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcBodyStream_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcBodyStream_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcBodyStream_0(ctx, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcBodyStream_0(ctx, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) }) @@ -1383,14 +1397,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcBodyStream_1(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcBodyStream_1(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcBodyStream_1(ctx, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcBodyStream_1(ctx, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) }) @@ -1406,14 +1421,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcBodyStream_2(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcBodyStream_2(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcBodyStream_2(ctx, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcBodyStream_2(ctx, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) }) @@ -1429,14 +1445,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcBodyStream_3(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcBodyStream_3(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcBodyStream_3(ctx, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcBodyStream_3(ctx, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) }) @@ -1452,14 +1469,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcBodyStream_4(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcBodyStream_4(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcBodyStream_4(ctx, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcBodyStream_4(ctx, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) }) @@ -1475,14 +1493,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcBodyStream_5(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcBodyStream_5(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcBodyStream_5(ctx, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcBodyStream_5(ctx, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) }) @@ -1498,14 +1517,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcBodyStream_6(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcBodyStream_6(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcBodyStream_6(ctx, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcBodyStream_6(ctx, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) }) @@ -1521,14 +1541,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcPathSingleNestedStream_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcPathSingleNestedStream_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcPathSingleNestedStream_0(ctx, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcPathSingleNestedStream_0(ctx, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) }) @@ -1544,14 +1565,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcPathNestedStream_0(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcPathNestedStream_0(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcPathNestedStream_0(ctx, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcPathNestedStream_0(ctx, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) }) @@ -1567,14 +1589,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcPathNestedStream_1(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcPathNestedStream_1(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcPathNestedStream_1(ctx, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcPathNestedStream_1(ctx, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) }) @@ -1590,14 +1613,15 @@ func RegisterFlowCombinationHandler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_FlowCombination_RpcPathNestedStream_2(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_FlowCombination_RpcPathNestedStream_2(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } - forward_FlowCombination_RpcPathNestedStream_2(ctx, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) + forward_FlowCombination_RpcPathNestedStream_2(ctx, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) }) diff --git a/protoc-gen-grpc-gateway/descriptor/types_test.go b/protoc-gen-grpc-gateway/descriptor/types_test.go index 8642ff23b19..4b7caea6f3d 100644 --- a/protoc-gen-grpc-gateway/descriptor/types_test.go +++ b/protoc-gen-grpc-gateway/descriptor/types_test.go @@ -20,6 +20,10 @@ func TestGoPackageStandard(t *testing.T) { pkg: GoPackage{Path: "encoding/json", Name: "json"}, want: true, }, + { + pkg: GoPackage{Path: "github.com/golang/protobuf/jsonpb", Name: "jsonpb"}, + want: false, + }, { pkg: GoPackage{Path: "golang.org/x/net/context", Name: "context"}, want: false, @@ -52,6 +56,10 @@ func TestGoPackageString(t *testing.T) { pkg: GoPackage{Path: "encoding/json", Name: "json"}, want: `"encoding/json"`, }, + { + pkg: GoPackage{Path: "github.com/golang/protobuf/jsonpb", Name: "jsonpb"}, + want: `"github.com/golang/protobuf/jsonpb"`, + }, { pkg: GoPackage{Path: "golang.org/x/net/context", Name: "context"}, want: `"golang.org/x/net/context"`, diff --git a/protoc-gen-grpc-gateway/gengateway/generator.go b/protoc-gen-grpc-gateway/gengateway/generator.go index 24245545f4c..33cf6cc65f1 100644 --- a/protoc-gen-grpc-gateway/gengateway/generator.go +++ b/protoc-gen-grpc-gateway/gengateway/generator.go @@ -28,7 +28,6 @@ type generator struct { func New(reg *descriptor.Registry) gen.Generator { var imports []descriptor.GoPackage for _, pkgpath := range []string{ - "encoding/json", "io", "net/http", "github.com/gengo/grpc-gateway/runtime", diff --git a/protoc-gen-grpc-gateway/gengateway/template.go b/protoc-gen-grpc-gateway/gengateway/template.go index 37bbc64544b..416c8c4e6cc 100644 --- a/protoc-gen-grpc-gateway/gengateway/template.go +++ b/protoc-gen-grpc-gateway/gengateway/template.go @@ -113,7 +113,6 @@ import ( var _ codes.Code var _ io.Reader var _ = runtime.String -var _ = json.Marshal var _ = utilities.NewDoubleArray `)) @@ -127,9 +126,9 @@ var _ = utilities.NewDoubleArray _ = template.Must(handlerTemplate.New("request-func-signature").Parse(strings.Replace(` {{if .Method.GetServerStreaming}} -func request_{{.Method.Service.GetName}}_{{.Method.GetName}}_{{.Index}}(ctx context.Context, client {{.Method.Service.GetName}}Client, req *http.Request, pathParams map[string]string) ({{.Method.Service.GetName}}_{{.Method.GetName}}Client, runtime.ServerMetadata, error) +func request_{{.Method.Service.GetName}}_{{.Method.GetName}}_{{.Index}}(ctx context.Context, marshaler runtime.Marshaler, client {{.Method.Service.GetName}}Client, req *http.Request, pathParams map[string]string) ({{.Method.Service.GetName}}_{{.Method.GetName}}Client, runtime.ServerMetadata, error) {{else}} -func request_{{.Method.Service.GetName}}_{{.Method.GetName}}_{{.Index}}(ctx context.Context, client {{.Method.Service.GetName}}Client, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) +func request_{{.Method.Service.GetName}}_{{.Method.GetName}}_{{.Index}}(ctx context.Context, marshaler runtime.Marshaler, client {{.Method.Service.GetName}}Client, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {{end}}`, "\n", "", -1))) _ = template.Must(handlerTemplate.New("client-streaming-request-func").Parse(` @@ -140,7 +139,7 @@ func request_{{.Method.Service.GetName}}_{{.Method.GetName}}_{{.Index}}(ctx cont grpclog.Printf("Failed to start streaming: %v", err) return nil, metadata, err } - dec := json.NewDecoder(req.Body) + dec := marshaler.NewDecoder(req.Body) for { var protoReq {{.Method.RequestType.GoType .Method.Service.File.GoPkg.Path}} err = dec.Decode(&protoReq) @@ -187,7 +186,7 @@ var ( var protoReq {{.Method.RequestType.GoType .Method.Service.File.GoPkg.Path}} var metadata runtime.ServerMetadata {{if .Body}} - if err := json.NewDecoder(req.Body).Decode(&{{.Body.RHS "protoReq"}}); err != nil { + if err := marshaler.NewDecoder(req.Body).Decode(&{{.Body.RHS "protoReq"}}); err != nil { return nil, metadata, grpc.Errorf(codes.InvalidArgument, "%v", err) } {{end}} @@ -280,16 +279,17 @@ func Register{{$svc.GetName}}Handler(ctx context.Context, mux *runtime.ServeMux, } }(ctx.Done(), cn.CloseNotify()) } - resp, md, err := request_{{$svc.GetName}}_{{$m.GetName}}_{{$b.Index}}(runtime.AnnotateContext(ctx, req), client, req, pathParams) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + resp, md, err := request_{{$svc.GetName}}_{{$m.GetName}}_{{$b.Index}}(runtime.AnnotateContext(ctx, req), inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { - runtime.HTTPError(ctx, w, req, err) + runtime.HTTPError(ctx, outboundMarshaler, w, req, err) return } {{if $m.GetServerStreaming}} - forward_{{$svc.GetName}}_{{$m.GetName}}_{{$b.Index}}(ctx, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) + forward_{{$svc.GetName}}_{{$m.GetName}}_{{$b.Index}}(ctx, outboundMarshaler, w, req, func() (proto.Message, error) { return resp.Recv() }, mux.GetForwardResponseOptions()...) {{else}} - forward_{{$svc.GetName}}_{{$m.GetName}}_{{$b.Index}}(ctx, w, req, resp, mux.GetForwardResponseOptions()...) + forward_{{$svc.GetName}}_{{$m.GetName}}_{{$b.Index}}(ctx, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) {{end}} }) {{end}} diff --git a/protoc-gen-grpc-gateway/gengateway/template_test.go b/protoc-gen-grpc-gateway/gengateway/template_test.go index c53d51e0eeb..cfad4312fee 100644 --- a/protoc-gen-grpc-gateway/gengateway/template_test.go +++ b/protoc-gen-grpc-gateway/gengateway/template_test.go @@ -133,11 +133,11 @@ func TestApplyTemplateRequestWithoutClientStreaming(t *testing.T) { }{ { serverStreaming: false, - sigWant: `func request_ExampleService_Echo_0(ctx context.Context, client ExampleServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {`, + sigWant: `func request_ExampleService_Echo_0(ctx context.Context, marshaler runtime.Marshaler, client ExampleServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {`, }, { serverStreaming: true, - sigWant: `func request_ExampleService_Echo_0(ctx context.Context, client ExampleServiceClient, req *http.Request, pathParams map[string]string) (ExampleService_EchoClient, runtime.ServerMetadata, error) {`, + sigWant: `func request_ExampleService_Echo_0(ctx context.Context, marshaler runtime.Marshaler, client ExampleServiceClient, req *http.Request, pathParams map[string]string) (ExampleService_EchoClient, runtime.ServerMetadata, error) {`, }, } { meth.ServerStreaming = proto.Bool(spec.serverStreaming) @@ -230,7 +230,7 @@ func TestApplyTemplateRequestWithoutClientStreaming(t *testing.T) { if want := spec.sigWant; !strings.Contains(got, want) { t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want) } - if want := `json.NewDecoder(req.Body).Decode(&protoReq.GetNested().Bool)`; !strings.Contains(got, want) { + if want := `marshaler.NewDecoder(req.Body).Decode(&protoReq.GetNested().Bool)`; !strings.Contains(got, want) { t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want) } if want := `val, ok = pathParams["nested.int32"]`; !strings.Contains(got, want) { @@ -294,11 +294,11 @@ func TestApplyTemplateRequestWithClientStreaming(t *testing.T) { }{ { serverStreaming: false, - sigWant: `func request_ExampleService_Echo_0(ctx context.Context, client ExampleServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {`, + sigWant: `func request_ExampleService_Echo_0(ctx context.Context, marshaler runtime.Marshaler, client ExampleServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {`, }, { serverStreaming: true, - sigWant: `func request_ExampleService_Echo_0(ctx context.Context, client ExampleServiceClient, req *http.Request, pathParams map[string]string) (ExampleService_EchoClient, runtime.ServerMetadata, error) {`, + sigWant: `func request_ExampleService_Echo_0(ctx context.Context, marshaler runtime.Marshaler, client ExampleServiceClient, req *http.Request, pathParams map[string]string) (ExampleService_EchoClient, runtime.ServerMetadata, error) {`, }, } { meth.ServerStreaming = proto.Bool(spec.serverStreaming) @@ -391,7 +391,7 @@ func TestApplyTemplateRequestWithClientStreaming(t *testing.T) { if want := spec.sigWant; !strings.Contains(got, want) { t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want) } - if want := `json.NewDecoder(req.Body)`; !strings.Contains(got, want) { + if want := `marshaler.NewDecoder(req.Body)`; !strings.Contains(got, want) { t.Errorf("applyTemplate(%#v) = %s; want to contain %s", file, got, want) } if want := `func RegisterExampleServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {`; !strings.Contains(got, want) { diff --git a/runtime/errors.go b/runtime/errors.go index 163fb8b8d62..4d19b645607 100644 --- a/runtime/errors.go +++ b/runtime/errors.go @@ -1,10 +1,11 @@ package runtime import ( - "encoding/json" "io" "net/http" + "github.com/golang/protobuf/proto" + "golang.org/x/net/context" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -67,22 +68,28 @@ type errorBody struct { Code int `json:"code"` } +//Make this also conform to proto.Message for builtin JSONPb Marshaler +func (e *errorBody) Reset() { *e = errorBody{} } +func (e *errorBody) String() string { return proto.CompactTextString(e) } +func (*errorBody) ProtoMessage() {} + // DefaultHTTPError is the default implementation of HTTPError. // If "err" is an error from gRPC system, the function replies with the status code mapped by HTTPStatusFromCode. // If otherwise, it replies with http.StatusInternalServerError. // // The response body returned by this function is a JSON object, // which contains a member whose key is "error" and whose value is err.Error(). -func DefaultHTTPError(ctx context.Context, w http.ResponseWriter, _ *http.Request, err error) { +func DefaultHTTPError(ctx context.Context, marshaler Marshaler, w http.ResponseWriter, _ *http.Request, err error) { const fallback = `{"error": "failed to marshal error message"}` w.Header().Del("Trailer") - w.Header().Set("Content-Type", "application/json") - body := errorBody{ + w.Header().Set("Content-Type", marshaler.ContentType()) + body := &errorBody{ Error: grpc.ErrorDesc(err), Code: int(grpc.Code(err)), } - buf, merr := json.Marshal(body) + + buf, merr := marshaler.Marshal(body) if merr != nil { grpclog.Printf("Failed to marshal error message %q: %v", body, merr) w.WriteHeader(http.StatusInternalServerError) diff --git a/runtime/errors_test.go b/runtime/errors_test.go index 9f5022aa3c9..3cc9acfde35 100644 --- a/runtime/errors_test.go +++ b/runtime/errors_test.go @@ -35,7 +35,7 @@ func TestDefaultHTTPError(t *testing.T) { } { w := httptest.NewRecorder() req, _ := http.NewRequest("", "", nil) // Pass in an empty request to match the signature - runtime.DefaultHTTPError(ctx, w, req, spec.err) + runtime.DefaultHTTPError(ctx, &runtime.JSONBuiltin{}, w, req, spec.err) if got, want := w.Header().Get("Content-Type"), "application/json"; got != want { t.Errorf(`w.Header().Get("Content-Type") = %q; want %q; on spec.err=%v`, got, want, spec.err) diff --git a/runtime/handler.go b/runtime/handler.go index 22aab23704b..ca113bc7c29 100644 --- a/runtime/handler.go +++ b/runtime/handler.go @@ -1,7 +1,6 @@ package runtime import ( - "encoding/json" "fmt" "io" "net/http" @@ -18,15 +17,25 @@ type responseStreamChunk struct { Error *responseStreamError `json:"error,omitempty"` } +//Make this also conform to proto.Message for builtin JSONPb Marshaler +func (m *responseStreamChunk) Reset() { *m = responseStreamChunk{} } +func (m *responseStreamChunk) String() string { return proto.CompactTextString(m) } +func (*responseStreamChunk) ProtoMessage() {} + type responseStreamError struct { - GrpcCode int `json:"grpc_code, omitempty"` - HTTPCode int `json:"http_code, omitempty"` - Message string `json:"message, omitempty"` - HTTPStatus string `json:"http_status, omitempty"` + GrpcCode int `json:"grpc_code,omitempty"` + HTTPCode int `json:"http_code,omitempty"` + Message string `json:"message,omitempty"` + HTTPStatus string `json:"http_status,omitempty"` } +//Make this also conform to proto.Message for builtin JSONPb Marshaler +func (m *responseStreamError) Reset() { *m = responseStreamError{} } +func (m *responseStreamError) String() string { return proto.CompactTextString(m) } +func (*responseStreamError) ProtoMessage() {} + // ForwardResponseStream forwards the stream from gRPC server to REST client. -func ForwardResponseStream(ctx context.Context, w http.ResponseWriter, req *http.Request, recv func() (proto.Message, error), opts ...func(context.Context, http.ResponseWriter, proto.Message) error) { +func ForwardResponseStream(ctx context.Context, marshaler Marshaler, w http.ResponseWriter, req *http.Request, recv func() (proto.Message, error), opts ...func(context.Context, http.ResponseWriter, proto.Message) error) { f, ok := w.(http.Flusher) if !ok { grpclog.Printf("Flush not supported in %T", w) @@ -43,7 +52,7 @@ func ForwardResponseStream(ctx context.Context, w http.ResponseWriter, req *http handleForwardResponseServerMetadata(w, md) w.Header().Set("Transfer-Encoding", "chunked") - w.Header().Set("Content-Type", "application/json") + w.Header().Set("Content-Type", marshaler.ContentType()) if err := handleForwardResponseOptions(ctx, w, nil, opts); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -56,14 +65,15 @@ func ForwardResponseStream(ctx context.Context, w http.ResponseWriter, req *http return } if err != nil { - handleForwardResponseStreamError(w, err) + handleForwardResponseStreamError(marshaler, w, err) return } if err := handleForwardResponseOptions(ctx, w, resp, opts); err != nil { - handleForwardResponseStreamError(w, err) + handleForwardResponseStreamError(marshaler, w, err) return } - buf, err := json.Marshal(responseStreamChunk{Result: resp}) + + buf, err := marshaler.Marshal(&responseStreamChunk{Result: resp}) if err != nil { grpclog.Printf("Failed to marshal response chunk: %v", err) return @@ -102,7 +112,7 @@ func handleForwardResponseTrailer(w http.ResponseWriter, md ServerMetadata) { } // ForwardResponseMessage forwards the message "resp" from gRPC server to REST client. -func ForwardResponseMessage(ctx context.Context, w http.ResponseWriter, req *http.Request, resp proto.Message, opts ...func(context.Context, http.ResponseWriter, proto.Message) error) { +func ForwardResponseMessage(ctx context.Context, marshaler Marshaler, w http.ResponseWriter, req *http.Request, resp proto.Message, opts ...func(context.Context, http.ResponseWriter, proto.Message) error) { md, ok := ServerMetadataFromContext(ctx) if !ok { grpclog.Printf("Failed to extract ServerMetadata from context") @@ -110,16 +120,16 @@ func ForwardResponseMessage(ctx context.Context, w http.ResponseWriter, req *htt handleForwardResponseServerMetadata(w, md) handleForwardResponseTrailerHeader(w, md) - w.Header().Set("Content-Type", "application/json") + w.Header().Set("Content-Type", marshaler.ContentType()) if err := handleForwardResponseOptions(ctx, w, resp, opts); err != nil { - HTTPError(ctx, w, req, err) + HTTPError(ctx, marshaler, w, req, err) return } - buf, err := json.Marshal(resp) + buf, err := marshaler.Marshal(resp) if err != nil { grpclog.Printf("Marshal error: %v", err) - HTTPError(ctx, w, req, err) + HTTPError(ctx, marshaler, w, req, err) return } @@ -143,17 +153,17 @@ func handleForwardResponseOptions(ctx context.Context, w http.ResponseWriter, re return nil } -func handleForwardResponseStreamError(w http.ResponseWriter, err error) { +func handleForwardResponseStreamError(marshaler Marshaler, w http.ResponseWriter, err error) { grpcCode := grpc.Code(err) httpCode := HTTPStatusFromCode(grpcCode) - resp := responseStreamChunk{ + resp := &responseStreamChunk{ Error: &responseStreamError{ GrpcCode: int(grpcCode), HTTPCode: httpCode, Message: err.Error(), HTTPStatus: http.StatusText(httpCode), }} - buf, merr := json.Marshal(resp) + buf, merr := marshaler.Marshal(resp) if merr != nil { grpclog.Printf("Failed to marshal an error: %v", merr) return diff --git a/runtime/marshaler.go b/runtime/marshaler.go new file mode 100644 index 00000000000..a2112776526 --- /dev/null +++ b/runtime/marshaler.go @@ -0,0 +1,307 @@ +package runtime + +import ( + "bytes" + "encoding/json" + "errors" + "io" + "net/http" + + "github.com/golang/protobuf/jsonpb" + "github.com/golang/protobuf/proto" +) + +const MIMEWILDCARD = "*" + +var inboundDefaultMarshaler = &JSONBuiltin{} +var outboundDefaultMarshaler = &JSONBuiltin{} +var contentTypeHeader = http.CanonicalHeaderKey("Content-Type") + +// Get the inbound/outbound marshalers for this request. Checks the registry on the ServeMux for +// the MIME type set by the Content-Type header. +// If it isn't set (or the request Content-Type is empty), checks for "*". +// If that isn't set, uses the ServerMux's InboundMarshaler/OutboundMarshaler. +// If there are multiple Content-Type headers set, choose the first one that it can +// exactly match in the registry. Otherwise, follows the above logic for "*"/InboundMarshaler/OutboundMarshaler. +func MarshalerForRequest(mux *ServeMux, r *http.Request) (inbound Marshaler, outbound Marshaler) { + + inbound = nil + outbound = nil + + headerVals := r.Header[contentTypeHeader] + + for _, val := range headerVals { + if mux.MIMERegistry != nil && mux.MIMERegistry.mimeMap != nil { + if m, ok := mux.MIMERegistry.mimeMap[val]; ok { + if inbound == nil && m.inbound != nil { + inbound = m.inbound + } + if outbound == nil && m.outbound != nil { + outbound = m.outbound + } + } + } else { + //Nil mimeMap, no need to bother checking for MIMEWILDCARD + if mux.InboundMarshaler == nil { + //Its nil, use our default + inbound = inboundDefaultMarshaler + } else { + inbound = mux.InboundMarshaler + } + + if mux.OutboundMarshaler == nil { + //Its nil, use our default + outbound = outboundDefaultMarshaler + } else { + outbound = mux.OutboundMarshaler + } + } + + if inbound != nil && outbound != nil { + //Got them both, return + return inbound, outbound + } + } + + if mux.MIMERegistry != nil && mux.MIMERegistry.mimeMap != nil { + if m, ok := mux.MIMERegistry.mimeMap[MIMEWILDCARD]; ok { + if inbound == nil && m.inbound != nil { + inbound = m.inbound + } + if outbound == nil && m.outbound != nil { + outbound = m.outbound + } + } + } + + //Haven't gotten anywhere with any of the headers or MIMEWILDCARD + //Try to use the mux, otherwise use our default + if inbound == nil { + if mux.InboundMarshaler == nil { + //Its nil, use our default + inbound = inboundDefaultMarshaler + } else { + inbound = mux.InboundMarshaler + } + } + + if outbound == nil { + if mux.OutboundMarshaler == nil { + //Its nil, use our default + outbound = outboundDefaultMarshaler + } else { + outbound = mux.OutboundMarshaler + } + } + + return inbound, outbound + +} + +type MarshalerMIMERegistry struct { + mimeMap map[string]*mimeMarshaler +} + +type mimeMarshaler struct { + inbound Marshaler + outbound Marshaler +} + +// Add an inbound and outbund marshaler for a case-sensitive MIME type string ("*" to match any MIME type). +// Inbound is the marshaler that is used when marshaling inbound requests from the client. +// Outbound is the marshaler that is used when marshaling outbound responses to the client. +func (m *MarshalerMIMERegistry) AddMarshaler(mime string, inbound Marshaler, outbound Marshaler) { + + if len(mime) == 0 { + panic("Mime can't be an empty string") + } + + m.mimeMap[mime] = &mimeMarshaler{ + inbound: inbound, + outbound: outbound, + } + +} + +// Add an inbound marshaler for a case-sensitive MIME type string ("*" to match any MIME type). +// Inbound is the marshaler that is used when marshaling inbound requests from the client. +func (m *MarshalerMIMERegistry) AddInboundMarshaler(mime string, inbound Marshaler) { + + if len(mime) == 0 { + panic("Mime can't be an empty string") + } + + if _, ok := m.mimeMap[mime]; ok { + //Already have this mime, just change inbound + m.mimeMap[mime].inbound = inbound + } else { + m.mimeMap[mime] = &mimeMarshaler{ + inbound: inbound, + outbound: nil, + } + } + +} + +// Add an outbund marshaler for a case-sensitive MIME type string ("*" to match any MIME type). +// Outbound is the marshaler that is used when marshaling outbound responses to the client. +func (m *MarshalerMIMERegistry) AddOutboundMarshaler(mime string, outbound Marshaler) { + mime = http.CanonicalHeaderKey(mime) + if len(mime) == 0 { + panic("Mime can't be an empty string") + } + + if _, ok := m.mimeMap[mime]; ok { + //Already have this mime, just change outbound + m.mimeMap[mime].outbound = outbound + } else { + m.mimeMap[mime] = &mimeMarshaler{ + inbound: nil, + outbound: outbound, + } + } + +} + +// Create a new MIME marshaler registry. Allows for a mapping of case-sensitive +// Content-Type MIME type string to runtime.Marshaler interfaces. +// For example, you could allow the client to specify the use of the runtime.JSONPb marshaler +// with a "applicaton/jsonpb" Content-Type and the use of the runtime.JSONBuiltin marshaler +// with a "application/json" Content-Type. +// "*" can be used to match any Content-Type. +// This can be attached to a ServerMux with the MIMERegistry option. +func NewMarshalerMIMERegistry() *MarshalerMIMERegistry { + return &MarshalerMIMERegistry{ + mimeMap: make(map[string]*mimeMarshaler), + } +} + +type Marshaler interface { + Marshal(v interface{}) ([]byte, error) + Unmarshal(data []byte, v interface{}) error + NewDecoder(r io.Reader) Decoder + NewEncoder(w io.Writer) Encoder + ContentType() string +} + +type Decoder interface { + Decode(v interface{}) error +} + +type Encoder interface { + Encode(v interface{}) error +} + +type JSONBuiltin struct{} + +func (*JSONBuiltin) ContentType() string { + return "application/json" +} + +func (j *JSONBuiltin) Marshal(v interface{}) ([]byte, error) { + return json.Marshal(v) +} + +func (j *JSONBuiltin) Unmarshal(data []byte, v interface{}) error { + return json.Unmarshal(data, v) +} + +func (j *JSONBuiltin) NewDecoder(r io.Reader) Decoder { + return json.NewDecoder(r) +} + +func (j *JSONBuiltin) NewEncoder(w io.Writer) Encoder { + return json.NewEncoder(w) +} + +type JSONPb struct { + // Whether to render enum values as integers, as opposed to string values. + EnumsAsInts bool + + // Whether to render fields with zero values. + EmitDefaults bool + + // A string to indent each level by. The presence of this field will + // also cause a space to appear between the field separator and + // value, and for newlines to be appear between fields and array + // elements. + Indent string + + // Whether to use the original (.proto) name for fields. + OrigName bool +} + +func (*JSONPb) ContentType() string { + return "application/json" +} + +func (j *JSONPb) Marshal(v interface{}) ([]byte, error) { + m := &jsonpb.Marshaler{ + EnumsAsInts: j.EnumsAsInts, + EmitDefaults: j.EmitDefaults, + Indent: j.Indent, + OrigName: j.OrigName, + } + if p, ok := v.(proto.Message); ok { + var buf bytes.Buffer + if err := m.Marshal(&buf, p); err != nil { + return nil, err + } + return buf.Bytes(), nil + } else { + return nil, errors.New("Interface is not proto.Message") + } + +} + +func (j *JSONPb) Unmarshal(data []byte, v interface{}) error { + r := bytes.NewReader(data) + if p, ok := v.(proto.Message); ok { + return jsonpb.Unmarshal(r, p) + } else { + return errors.New("Interface is not proto.Message") + } +} + +func (j *JSONPb) NewDecoder(r io.Reader) Decoder { + return &JSONPbDecoder{decoder: json.NewDecoder(r)} +} + +func (j *JSONPb) NewEncoder(w io.Writer) Encoder { + m := &jsonpb.Marshaler{ + EnumsAsInts: j.EnumsAsInts, + EmitDefaults: j.EmitDefaults, + Indent: j.Indent, + OrigName: j.OrigName, + } + + return &JSONPbEncoder{ + marshal: m, + writer: w, + } +} + +type JSONPbDecoder struct { + decoder *json.Decoder +} + +func (j *JSONPbDecoder) Decode(v interface{}) error { + if p, ok := v.(proto.Message); ok { + return jsonpb.UnmarshalNext(j.decoder, p) + } else { + return errors.New("Interface is not proto.Message") + } +} + +type JSONPbEncoder struct { + marshal *jsonpb.Marshaler + writer io.Writer +} + +func (j *JSONPbEncoder) Encode(v interface{}) error { + if p, ok := v.(proto.Message); ok { + return j.marshal.Marshal(j.writer, p) + } else { + return errors.New("Interface is not proto.Message") + } +} diff --git a/runtime/mux.go b/runtime/mux.go index e9c1c5a7ba7..943c8916122 100644 --- a/runtime/mux.go +++ b/runtime/mux.go @@ -18,6 +18,13 @@ type ServeMux struct { // handlers maps HTTP method to a list of handlers. handlers map[string][]handler forwardResponseOptions []func(context.Context, http.ResponseWriter, proto.Message) error + // InboundMarshaler is the marshaler that is used when marshaling inbound requests from + // a client. Defaults to runtime.JSONBuiltin + InboundMarshaler Marshaler + // OutbutMarshaler is the marshaler that is used when marshaling outbound responses to + // a client. Defaults to runtime.JSONBuiltin + OutboundMarshaler Marshaler + MIMERegistry *MarshalerMIMERegistry } // ServeMuxOption is an option that can be given to a ServeMux on construction. @@ -35,12 +42,16 @@ func WithForwardResponseOption(forwardResponseOption func(context.Context, http. } } -// NewServeMux returns a new MuxHandler whose internal mapping is empty. +// NewServeMux returns a new ServeMux whose internal mapping is empty. func NewServeMux(opts ...ServeMuxOption) *ServeMux { serveMux := &ServeMux{ handlers: make(map[string][]handler), forwardResponseOptions: make([]func(context.Context, http.ResponseWriter, proto.Message) error, 0), + InboundMarshaler: &JSONBuiltin{}, + OutboundMarshaler: &JSONBuiltin{}, + MIMERegistry: nil, } + for _, opt := range opts { opt(serveMux) }