diff --git a/cmd/protoc-gen-dyn-gin/main.go b/cmd/protoc-gen-dyn-gin/main.go index be2e7e1..bdb19b7 100644 --- a/cmd/protoc-gen-dyn-gin/main.go +++ b/cmd/protoc-gen-dyn-gin/main.go @@ -7,7 +7,7 @@ import ( "google.golang.org/protobuf/compiler/protogen" ) -const version = "v0.1.0" +const version = "v0.2.0" var args = struct { ShowVersion bool diff --git a/cmd/protoc-gen-dyn-gin/service.go b/cmd/protoc-gen-dyn-gin/service.go index 4230d96..43d7e51 100644 --- a/cmd/protoc-gen-dyn-gin/service.go +++ b/cmd/protoc-gen-dyn-gin/service.go @@ -78,9 +78,6 @@ func executeServiceDesc(g *protogen.GeneratedFile, s *serviceDesc) error { { // gin.HandleFunc closure g.P("return func(c *", g.QualifiedGoIdent(ginPackage.Ident("Context")), ") {") g.P("carrier := ", g.QualifiedGoIdent(transportHttpPackage.Ident("FromCarrier")), "(c.Request.Context())") - if s.UseEncoding && m.HasVars { - g.P("c.Request = carrier.WithValueUri(c.Request, c.Params)") - } { // binding g.P("shouldBind := func(req *", m.Request, ") error {") if s.UseEncoding { @@ -101,7 +98,7 @@ func executeServiceDesc(g *protogen.GeneratedFile, s *serviceDesc) error { } } if m.HasVars { - g.P("if err := carrier.BindUri(c, req); err != nil {") + g.P("if err := carrier.BindURI(c, " + g.QualifiedGoIdent(transportHttpPackage.Ident("UrlValues")) + "(c.Params), req); err != nil {") g.P("return err") g.P("}") } diff --git a/example/hello/gen.sh b/example/hello/gen.sh index 3825fc1..1d6a626 100755 --- a/example/hello/gen.sh +++ b/example/hello/gen.sh @@ -18,6 +18,7 @@ protoc \ --go-grpc_opt paths=source_relative \ --dyn-gin_out ${out_dir} \ --dyn-gin_opt paths=source_relative \ + --dyn-gin_opt use_encoding=true \ --dyn-resty_out ${out_dir} \ --dyn-resty_opt paths=source_relative \ hello.proto diff --git a/example/hello/hello.gin.pb.go b/example/hello/hello.gin.pb.go index cb5e232..8cb1b52 100644 --- a/example/hello/hello.gin.pb.go +++ b/example/hello/hello.gin.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-dyn-gin. DO NOT EDIT. // versions: -// - protoc-gen-dyn-gin v0.1.0 -// - protoc v4.24.0 +// - protoc-gen-dyn-gin v0.2.0 +// - protoc v4.25.3 // source: hello.proto package examples @@ -25,12 +25,15 @@ type GreeterHTTPServer interface { // SayHello Sends a hello // I am a trailing comment SayHello(context.Context, *HelloRequest) (*HelloReply, error) + // GetHello Sends a hello + GetHello(context.Context, *GetHelloRequest) (*GetHelloReply, error) } func RegisterGreeterHTTPServer(g *gin.RouterGroup, srv GreeterHTTPServer) { r := g.Group("") { r.POST("/v1/hello", _Greeter_SayHello0_HTTP_Handler(srv)) + r.GET("/v1/hello/:id", _Greeter_GetHello0_HTTP_Handler(srv)) } } @@ -38,7 +41,7 @@ func _Greeter_SayHello0_HTTP_Handler(srv GreeterHTTPServer) gin.HandlerFunc { return func(c *gin.Context) { carrier := http.FromCarrier(c.Request.Context()) shouldBind := func(req *HelloRequest) error { - if err := c.ShouldBind(req); err != nil { + if err := carrier.Bind(c, req); err != nil { return err } return carrier.Validate(c.Request.Context(), req) @@ -60,3 +63,33 @@ func _Greeter_SayHello0_HTTP_Handler(srv GreeterHTTPServer) gin.HandlerFunc { carrier.Render(c, reply) } } + +func _Greeter_GetHello0_HTTP_Handler(srv GreeterHTTPServer) gin.HandlerFunc { + return func(c *gin.Context) { + carrier := http.FromCarrier(c.Request.Context()) + shouldBind := func(req *GetHelloRequest) error { + if err := carrier.BindQuery(c, req); err != nil { + return err + } + if err := carrier.BindURI(c, http.UrlValues(c.Params), req); err != nil { + return err + } + return carrier.Validate(c.Request.Context(), req) + } + + var err error + var req GetHelloRequest + var reply *GetHelloReply + + if err = shouldBind(&req); err != nil { + carrier.Error(c, err) + return + } + reply, err = srv.GetHello(c.Request.Context(), &req) + if err != nil { + carrier.Error(c, err) + return + } + carrier.Render(c, reply) + } +} diff --git a/example/hello/hello.pb.go b/example/hello/hello.pb.go index 5126443..4ee0835 100644 --- a/example/hello/hello.pb.go +++ b/example/hello/hello.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.31.0 -// protoc v4.24.0 +// protoc-gen-go v1.28.1 +// protoc v4.25.3 // source: hello.proto package examples @@ -117,6 +117,102 @@ func (x *HelloReply) GetMessage() string { return "" } +// The request message containing the user's name. +type GetHelloRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *GetHelloRequest) Reset() { + *x = GetHelloRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_hello_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetHelloRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetHelloRequest) ProtoMessage() {} + +func (x *GetHelloRequest) ProtoReflect() protoreflect.Message { + mi := &file_hello_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetHelloRequest.ProtoReflect.Descriptor instead. +func (*GetHelloRequest) Descriptor() ([]byte, []int) { + return file_hello_proto_rawDescGZIP(), []int{2} +} + +func (x *GetHelloRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +// The response message containing the greetings +type GetHelloReply struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` +} + +func (x *GetHelloReply) Reset() { + *x = GetHelloReply{} + if protoimpl.UnsafeEnabled { + mi := &file_hello_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetHelloReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetHelloReply) ProtoMessage() {} + +func (x *GetHelloReply) ProtoReflect() protoreflect.Message { + mi := &file_hello_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetHelloReply.ProtoReflect.Descriptor instead. +func (*GetHelloReply) Descriptor() ([]byte, []int) { + return file_hello_proto_rawDescGZIP(), []int{3} +} + +func (x *GetHelloReply) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + var File_hello_proto protoreflect.FileDescriptor var file_hello_proto_rawDesc = []byte{ @@ -128,18 +224,29 @@ var file_hello_proto_rawDesc = []byte{ 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x26, 0x0a, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, - 0x61, 0x67, 0x65, 0x32, 0x5d, 0x0a, 0x07, 0x47, 0x72, 0x65, 0x65, 0x74, 0x65, 0x72, 0x12, 0x52, - 0x0a, 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x18, 0x2e, 0x68, 0x65, 0x6c, - 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, - 0x64, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x14, 0x82, 0xd3, - 0xe4, 0x93, 0x02, 0x0e, 0x3a, 0x01, 0x2a, 0x22, 0x09, 0x2f, 0x76, 0x31, 0x2f, 0x68, 0x65, 0x6c, - 0x6c, 0x6f, 0x42, 0x4e, 0x0a, 0x1a, 0x69, 0x6f, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x74, 0x68, - 0x69, 0x6e, 0x67, 0x73, 0x2d, 0x67, 0x6f, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, - 0x42, 0x0f, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x50, 0x72, 0x6f, 0x74, - 0x6f, 0x50, 0x01, 0x5a, 0x1d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, - 0x74, 0x68, 0x69, 0x6e, 0x67, 0x73, 0x2d, 0x67, 0x6f, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, - 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x61, 0x67, 0x65, 0x22, 0x21, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x22, 0x29, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x48, 0x65, 0x6c, + 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, + 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, + 0x65, 0x32, 0xb9, 0x01, 0x0a, 0x07, 0x47, 0x72, 0x65, 0x65, 0x74, 0x65, 0x72, 0x12, 0x52, 0x0a, + 0x08, 0x53, 0x61, 0x79, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x18, 0x2e, 0x68, 0x65, 0x6c, 0x6c, + 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, + 0x2e, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x14, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x0e, 0x22, 0x09, 0x2f, 0x76, 0x31, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x3a, 0x01, + 0x2a, 0x12, 0x5a, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x1b, 0x2e, + 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x47, 0x65, 0x74, 0x48, 0x65, + 0x6c, 0x6c, 0x6f, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, 0x68, 0x65, 0x6c, + 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x47, 0x65, 0x74, 0x48, 0x65, 0x6c, 0x6c, 0x6f, + 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x16, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x10, 0x12, 0x0e, 0x2f, + 0x76, 0x31, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2f, 0x7b, 0x69, 0x64, 0x7d, 0x42, 0x4e, 0x0a, + 0x1a, 0x69, 0x6f, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x2e, 0x74, 0x68, 0x69, 0x6e, 0x67, 0x73, 0x2d, + 0x67, 0x6f, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x42, 0x0f, 0x48, 0x65, 0x6c, + 0x6c, 0x6f, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x1d, + 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x74, 0x68, 0x69, 0x6e, 0x67, + 0x73, 0x2d, 0x67, 0x6f, 0x2f, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -154,16 +261,20 @@ func file_hello_proto_rawDescGZIP() []byte { return file_hello_proto_rawDescData } -var file_hello_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_hello_proto_msgTypes = make([]protoimpl.MessageInfo, 4) var file_hello_proto_goTypes = []interface{}{ - (*HelloRequest)(nil), // 0: helloworld.HelloRequest - (*HelloReply)(nil), // 1: helloworld.HelloReply + (*HelloRequest)(nil), // 0: helloworld.HelloRequest + (*HelloReply)(nil), // 1: helloworld.HelloReply + (*GetHelloRequest)(nil), // 2: helloworld.GetHelloRequest + (*GetHelloReply)(nil), // 3: helloworld.GetHelloReply } var file_hello_proto_depIdxs = []int32{ 0, // 0: helloworld.Greeter.SayHello:input_type -> helloworld.HelloRequest - 1, // 1: helloworld.Greeter.SayHello:output_type -> helloworld.HelloReply - 1, // [1:2] is the sub-list for method output_type - 0, // [0:1] is the sub-list for method input_type + 2, // 1: helloworld.Greeter.GetHello:input_type -> helloworld.GetHelloRequest + 1, // 2: helloworld.Greeter.SayHello:output_type -> helloworld.HelloReply + 3, // 3: helloworld.Greeter.GetHello:output_type -> helloworld.GetHelloReply + 2, // [2:4] is the sub-list for method output_type + 0, // [0:2] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name @@ -199,6 +310,30 @@ func file_hello_proto_init() { return nil } } + file_hello_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetHelloRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_hello_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetHelloReply); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -206,7 +341,7 @@ func file_hello_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_hello_proto_rawDesc, NumEnums: 0, - NumMessages: 2, + NumMessages: 4, NumExtensions: 0, NumServices: 1, }, diff --git a/example/hello/hello.proto b/example/hello/hello.proto index 8bc0f73..0345f8f 100644 --- a/example/hello/hello.proto +++ b/example/hello/hello.proto @@ -12,20 +12,28 @@ import "google/api/annotations.proto"; // The greeting service definition. service Greeter { // Sends a hello - rpc SayHello (HelloRequest) returns (HelloReply) {// I am a trailing comment + rpc SayHello(HelloRequest) returns (HelloReply) { // I am a trailing comment option (google.api.http) = { - post: "/v1/hello", - body: "*" + post : "/v1/hello", + body : "*" + }; + } + // Sends a hello + rpc GetHello(GetHelloRequest) returns (GetHelloReply) { + option (google.api.http) = { + get : "/v1/hello/{id}", }; } } // The request message containing the user's name. -message HelloRequest { - string name = 1; -} +message HelloRequest { string name = 1; } + +// The response message containing the greetings +message HelloReply { string message = 1; } + +// The request message containing the user's name. +message GetHelloRequest { int64 id = 1; } // The response message containing the greetings -message HelloReply { - string message = 1; -} \ No newline at end of file +message GetHelloReply { string message = 1; } \ No newline at end of file diff --git a/example/hello/hello.resty.pb.go b/example/hello/hello.resty.pb.go index 6484259..9e3083a 100644 --- a/example/hello/hello.resty.pb.go +++ b/example/hello/hello.resty.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-dyn-resty. DO NOT EDIT. // versions: // - protoc-gen-dyn-resty v0.2.0 -// - protoc v4.24.0 +// - protoc v4.25.3 // source: hello.proto package examples @@ -22,6 +22,8 @@ type GreeterHTTPClient interface { // SayHello Sends a hello // I am a trailing comment SayHello(context.Context, *HelloRequest, ...http.CallOption) (*HelloReply, error) + // GetHello Sends a hello + GetHello(context.Context, *GetHelloRequest, ...http.CallOption) (*GetHelloReply, error) } type GreeterHTTPClientImpl struct { @@ -48,3 +50,17 @@ func (c *GreeterHTTPClientImpl) SayHello(ctx context.Context, req *HelloRequest, } return &resp, nil } + +// GetHello Sends a hello +func (c *GreeterHTTPClientImpl) GetHello(ctx context.Context, req *GetHelloRequest, opts ...http.CallOption) (*GetHelloReply, error) { + var err error + var resp GetHelloReply + + settings := c.cc.CallSetting("/v1/hello/{id}", opts...) + path := c.cc.EncodeURL(settings.Path, req, true) + err = c.cc.Invoke(ctx, "GET", path, nil, &resp, settings) + if err != nil { + return nil, err + } + return &resp, nil +} diff --git a/example/hello/hello_grpc.pb.go b/example/hello/hello_grpc.pb.go index 9d65995..9e686ce 100644 --- a/example/hello/hello_grpc.pb.go +++ b/example/hello/hello_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.2.0 -// - protoc v4.24.0 +// - protoc v4.25.3 // source: hello.proto package examples @@ -24,6 +24,8 @@ const _ = grpc.SupportPackageIsVersion7 type GreeterClient interface { // Sends a hello SayHello(ctx context.Context, in *HelloRequest, opts ...grpc.CallOption) (*HelloReply, error) + // Sends a hello + GetHello(ctx context.Context, in *GetHelloRequest, opts ...grpc.CallOption) (*GetHelloReply, error) } type greeterClient struct { @@ -43,12 +45,23 @@ func (c *greeterClient) SayHello(ctx context.Context, in *HelloRequest, opts ... return out, nil } +func (c *greeterClient) GetHello(ctx context.Context, in *GetHelloRequest, opts ...grpc.CallOption) (*GetHelloReply, error) { + out := new(GetHelloReply) + err := c.cc.Invoke(ctx, "/helloworld.Greeter/GetHello", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // GreeterServer is the server API for Greeter service. // All implementations must embed UnimplementedGreeterServer // for forward compatibility type GreeterServer interface { // Sends a hello SayHello(context.Context, *HelloRequest) (*HelloReply, error) + // Sends a hello + GetHello(context.Context, *GetHelloRequest) (*GetHelloReply, error) mustEmbedUnimplementedGreeterServer() } @@ -59,6 +72,9 @@ type UnimplementedGreeterServer struct { func (UnimplementedGreeterServer) SayHello(context.Context, *HelloRequest) (*HelloReply, error) { return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") } +func (UnimplementedGreeterServer) GetHello(context.Context, *GetHelloRequest) (*GetHelloReply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetHello not implemented") +} func (UnimplementedGreeterServer) mustEmbedUnimplementedGreeterServer() {} // UnsafeGreeterServer may be embedded to opt out of forward compatibility for this service. @@ -90,6 +106,24 @@ func _Greeter_SayHello_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +func _Greeter_GetHello_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetHelloRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(GreeterServer).GetHello(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/helloworld.Greeter/GetHello", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(GreeterServer).GetHello(ctx, req.(*GetHelloRequest)) + } + return interceptor(ctx, in, info, handler) +} + // Greeter_ServiceDesc is the grpc.ServiceDesc for Greeter service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -101,6 +135,10 @@ var Greeter_ServiceDesc = grpc.ServiceDesc{ MethodName: "SayHello", Handler: _Greeter_SayHello_Handler, }, + { + MethodName: "GetHello", + Handler: _Greeter_GetHello_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "hello.proto", diff --git a/transport/http/carrier.go b/transport/http/carrier.go index 49796d5..98fdb40 100644 --- a/transport/http/carrier.go +++ b/transport/http/carrier.go @@ -26,7 +26,7 @@ type Carrier interface { // // Deprecated: Use BindURI not need this. BindUri(*gin.Context, any) error - // Deprecated: Use BindURI not need this. + // BindUri binds the passed struct pointer using the uri codec.Marshaler. BindURI(*gin.Context, url.Values, any) error // Error encode error response. Error(*gin.Context, error) diff --git a/transport/http/encoding.go b/transport/http/encoding.go index 94c6f75..fcacfc7 100644 --- a/transport/http/encoding.go +++ b/transport/http/encoding.go @@ -9,6 +9,7 @@ import ( "github.com/things-go/encoding" ) +// Deprecated: Because BindUri is deprecated. func WithValueUri(req *http.Request, params gin.Params) *http.Request { vars := make(url.Values, len(params)) for _, p := range params { @@ -16,3 +17,11 @@ func WithValueUri(req *http.Request, params gin.Params) *http.Request { } return encoding.RequestWithUri(req, vars) } + +func UrlValues(params gin.Params) url.Values { + vars := make(url.Values, len(params)) + for _, p := range params { + vars.Add(p.Key, p.Value) + } + return vars +}