Skip to content

Commit

Permalink
feat: drop context uri params, use BindURI direct
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkgos committed Apr 25, 2024
1 parent 27e9be6 commit 0cff626
Show file tree
Hide file tree
Showing 10 changed files with 278 additions and 41 deletions.
2 changes: 1 addition & 1 deletion cmd/protoc-gen-dyn-gin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions cmd/protoc-gen-dyn-gin/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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("}")
}
Expand Down
1 change: 1 addition & 0 deletions example/hello/gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 36 additions & 3 deletions example/hello/hello.gin.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

177 changes: 156 additions & 21 deletions example/hello/hello.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 17 additions & 9 deletions example/hello/hello.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
message GetHelloReply { string message = 1; }
Loading

0 comments on commit 0cff626

Please sign in to comment.