From b1e1fa7848dddfd5764b1d6a391fb0d4c281d4be Mon Sep 17 00:00:00 2001 From: FynnTang Date: Tue, 29 Aug 2023 18:31:50 +0800 Subject: [PATCH] feat: add OriginalComment --- protoc-gen-go-http/http.go | 20 ++++++++++---------- protoc-gen-go-http/template.go | 16 ++++++++-------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/protoc-gen-go-http/http.go b/protoc-gen-go-http/http.go index 93e9b7c..7aa4673 100644 --- a/protoc-gen-go-http/http.go +++ b/protoc-gen-go-http/http.go @@ -207,16 +207,16 @@ func buildMethodDesc(g *protogen.GeneratedFile, m *protogen.Method, method, path 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, - Comment2: m.Comments.Trailing.String(), - Path: replacePathToGinPath(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), + Comment: comment, + OriginalComment: strings.ReplaceAll(comment, string(m.Desc.Name())+" ", ""), + Path: replacePathToGinPath(path), + Method: method, + HasVars: len(vars) > 0, } } diff --git a/protoc-gen-go-http/template.go b/protoc-gen-go-http/template.go index 1d886cf..f8a38e2 100644 --- a/protoc-gen-go-http/template.go +++ b/protoc-gen-go-http/template.go @@ -11,7 +11,7 @@ var httpTemplate = ` {{$svrName := .ServiceName}} {{- range .MethodSets}} -const Route{{$svrType}}{{.OriginalName}} = "{{.Path}}" {{- if ne .Comment2 ""}} {{.Comment2}} {{- end}} +const Route{{$svrType}}{{.OriginalName}} = "{{.Path}}" {{- if ne .OriginalComment ""}} {{.OriginalComment}} {{- end}} {{- end}} type {{.ServiceType}}HTTPServer interface { @@ -102,13 +102,13 @@ type serviceDesc struct { type methodDesc struct { // method - Name string - OriginalName string // The parsed original name - Num int - Request string - Reply string - Comment string - Comment2 string + Name string + OriginalName string // The parsed original name + Num int + Request string + Reply string + Comment string + OriginalComment string // http_rule Path string Method string