fix:#1987 Http and grpc generate route alignment (#1988)

* fix:#1987

* fix:explicit naming

* Update template.go

* Update template.go
status-code-override
songzhibin97 3 years ago committed by chenzhihui
parent a2765e27b4
commit bcf98570fe
  1. 1
      cmd/protoc-gen-go-http/http.go
  2. 5
      cmd/protoc-gen-go-http/template.go

@ -193,6 +193,7 @@ func buildMethodDesc(g *protogen.GeneratedFile, m *protogen.Method, method, path
}
return &methodDesc{
Name: m.GoName,
OriginalName: string(m.Desc.Name()),
Num: methodSets[m.GoName],
Request: g.QualifiedGoIdent(m.Input.GoIdent),
Reply: g.QualifiedGoIdent(m.Output.GoIdent),

@ -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...)
@ -105,6 +105,7 @@ type serviceDesc struct {
type methodDesc struct {
// method
Name string
OriginalName string // The parsed original name
Num int
Request string
Reply string

Loading…
Cancel
Save