Skip to content

Commit

Permalink
feat: add comment to http server interface method (#2657)
Browse files Browse the repository at this point in the history
Co-authored-by: gogogo <gogogo@aliyun.com>
  • Loading branch information
thinkgos and gogogo committed Feb 21, 2023
1 parent 54f19c1 commit d0b1d84
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/protoc-gen-go-http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions cmd/protoc-gen-go-http/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}
Expand Down Expand Up @@ -114,6 +117,7 @@ type methodDesc struct {
Num int
Request string
Reply string
Comment string
// http_rule
Path string
Method string
Expand Down

0 comments on commit d0b1d84

Please sign in to comment.