From d0b1d8485029ef251deb7112fb7ef4deb5d8abb6 Mon Sep 17 00:00:00 2001 From: thinkgo <49174849+thinkgos@users.noreply.github.com> Date: Tue, 21 Feb 2023 18:24:26 +0800 Subject: [PATCH] feat: add comment to http server interface method (#2657) Co-authored-by: gogogo --- cmd/protoc-gen-go-http/http.go | 5 +++++ cmd/protoc-gen-go-http/template.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/cmd/protoc-gen-go-http/http.go b/cmd/protoc-gen-go-http/http.go index 1c9298bf7..7a4ff7126 100644 --- a/cmd/protoc-gen-go-http/http.go +++ b/cmd/protoc-gen-go-http/http.go @@ -198,12 +198,17 @@ func buildMethodDesc(g *protogen.GeneratedFile, m *protogen.Method, method, path } } } + comment := m.Comments.Leading.String() + m.Comments.Trailing.String() + if comment != "" { + comment = "// " + m.GoName + strings.TrimPrefix(strings.TrimSuffix(comment, "\n"), "//") + } 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), + Comment: comment, 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 794210852..48f335755 100644 --- a/cmd/protoc-gen-go-http/template.go +++ b/cmd/protoc-gen-go-http/template.go @@ -16,6 +16,9 @@ const Operation{{$svrType}}{{.OriginalName}} = "/{{$svrName}}/{{.OriginalName}}" type {{.ServiceType}}HTTPServer interface { {{- range .MethodSets}} + {{- if ne .Comment ""}} + {{.Comment}} + {{- end}} {{.Name}}(context.Context, *{{.Request}}) (*{{.Reply}}, error) {{- end}} } @@ -114,6 +117,7 @@ type methodDesc struct { Num int Request string Reply string + Comment string // http_rule Path string Method string