From bcf98570fe93b20bf87547c0b94af9c938ca959d Mon Sep 17 00:00:00 2001 From: songzhibin97 <49082129+songzhibin97@users.noreply.github.com> Date: Thu, 19 May 2022 22:40:36 +0800 Subject: [PATCH] fix:#1987 Http and grpc generate route alignment (#1988) * fix:#1987 * fix:explicit naming * Update template.go * Update template.go --- cmd/protoc-gen-go-http/http.go | 15 ++++++++------- cmd/protoc-gen-go-http/template.go | 13 +++++++------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/cmd/protoc-gen-go-http/http.go b/cmd/protoc-gen-go-http/http.go index eb3fa89e3..fca4a63c1 100644 --- a/cmd/protoc-gen-go-http/http.go +++ b/cmd/protoc-gen-go-http/http.go @@ -192,13 +192,14 @@ func buildMethodDesc(g *protogen.GeneratedFile, m *protogen.Method, method, path } } return &methodDesc{ - Name: m.GoName, - Num: methodSets[m.GoName], - Request: g.QualifiedGoIdent(m.Input.GoIdent), - Reply: g.QualifiedGoIdent(m.Output.GoIdent), - Path: path, - Method: method, - HasVars: len(vars) > 0, + Name: m.GoName, + OriginalName: string(m.Desc.Name()), + Num: methodSets[m.GoName], + Request: g.QualifiedGoIdent(m.Input.GoIdent), + Reply: g.QualifiedGoIdent(m.Output.GoIdent), + Path: path, + Method: method, + HasVars: len(vars) > 0, } } diff --git a/cmd/protoc-gen-go-http/template.go b/cmd/protoc-gen-go-http/template.go index 50671e57e..d2ffcd41d 100644 --- a/cmd/protoc-gen-go-http/template.go +++ b/cmd/protoc-gen-go-http/template.go @@ -46,7 +46,7 @@ func _{{$svrType}}_{{.Name}}{{.Num}}_HTTP_Handler(srv {{$svrType}}HTTPServer) fu return err } {{- end}} - http.SetOperation(ctx,"/{{$svrName}}/{{.Name}}") + http.SetOperation(ctx,"/{{$svrName}}/{{.OriginalName}}") h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { return srv.{{.Name}}(ctx, req.(*{{.Request}})) }) @@ -79,7 +79,7 @@ func (c *{{$svrType}}HTTPClientImpl) {{.Name}}(ctx context.Context, in *{{.Reque var out {{.Reply}} pattern := "{{.Path}}" path := binding.EncodeURL(pattern, in, {{not .HasBody}}) - opts = append(opts, http.Operation("/{{$svrName}}/{{.Name}}")) + opts = append(opts, http.Operation("/{{$svrName}}/{{.OriginalName}}")) opts = append(opts, http.PathTemplate(pattern)) {{if .HasBody -}} err := c.cc.Invoke(ctx, "{{.Method}}", path, in{{.Body}}, &out{{.ResponseBody}}, opts...) @@ -104,10 +104,11 @@ type serviceDesc struct { type methodDesc struct { // method - Name string - Num int - Request string - Reply string + Name string + OriginalName string // The parsed original name + Num int + Request string + Reply string // http_rule Path string Method string