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

* fix:#1987

* fix:explicit naming

* Update template.go

* Update template.go
pull/2000/head
songzhibin97 3 years ago committed by GitHub
parent ec78198050
commit 8ff5f2fe88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      cmd/protoc-gen-go-http/http.go
  2. 13
      cmd/protoc-gen-go-http/template.go

@ -192,13 +192,14 @@ func buildMethodDesc(g *protogen.GeneratedFile, m *protogen.Method, method, path
} }
} }
return &methodDesc{ return &methodDesc{
Name: m.GoName, Name: m.GoName,
Num: methodSets[m.GoName], OriginalName: string(m.Desc.Name()),
Request: g.QualifiedGoIdent(m.Input.GoIdent), Num: methodSets[m.GoName],
Reply: g.QualifiedGoIdent(m.Output.GoIdent), Request: g.QualifiedGoIdent(m.Input.GoIdent),
Path: path, Reply: g.QualifiedGoIdent(m.Output.GoIdent),
Method: method, Path: path,
HasVars: len(vars) > 0, Method: method,
HasVars: len(vars) > 0,
} }
} }

@ -46,7 +46,7 @@ func _{{$svrType}}_{{.Name}}{{.Num}}_HTTP_Handler(srv {{$svrType}}HTTPServer) fu
return err return err
} }
{{- end}} {{- end}}
http.SetOperation(ctx,"/{{$svrName}}/{{.Name}}") http.SetOperation(ctx,"/{{$svrName}}/{{.OriginalName}}")
h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) { h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.{{.Name}}(ctx, req.(*{{.Request}})) return srv.{{.Name}}(ctx, req.(*{{.Request}}))
}) })
@ -79,7 +79,7 @@ func (c *{{$svrType}}HTTPClientImpl) {{.Name}}(ctx context.Context, in *{{.Reque
var out {{.Reply}} var out {{.Reply}}
pattern := "{{.Path}}" pattern := "{{.Path}}"
path := binding.EncodeURL(pattern, in, {{not .HasBody}}) 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)) opts = append(opts, http.PathTemplate(pattern))
{{if .HasBody -}} {{if .HasBody -}}
err := c.cc.Invoke(ctx, "{{.Method}}", path, in{{.Body}}, &out{{.ResponseBody}}, opts...) err := c.cc.Invoke(ctx, "{{.Method}}", path, in{{.Body}}, &out{{.ResponseBody}}, opts...)
@ -104,10 +104,11 @@ type serviceDesc struct {
type methodDesc struct { type methodDesc struct {
// method // method
Name string Name string
Num int OriginalName string // The parsed original name
Request string Num int
Reply string Request string
Reply string
// http_rule // http_rule
Path string Path string
Method string Method string

Loading…
Cancel
Save