From addcbba66e553f820a53a27b7a31e577f06bf2b8 Mon Sep 17 00:00:00 2001 From: haiyux Date: Mon, 4 Jul 2022 23:28:26 +0800 Subject: [PATCH] feat: add protoc-gen-go-http annotations synchronization with protoc-gen-go-grpc (#2151) --- cmd/protoc-gen-go-http/http.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/cmd/protoc-gen-go-http/http.go b/cmd/protoc-gen-go-http/http.go index fca4a63c1..3eb91c061 100644 --- a/cmd/protoc-gen-go-http/http.go +++ b/cmd/protoc-gen-go-http/http.go @@ -31,7 +31,13 @@ func generateFile(gen *protogen.Plugin, file *protogen.File, omitempty bool) *pr g := gen.NewGeneratedFile(filename, file.GoImportPath) g.P("// Code generated by protoc-gen-go-http. DO NOT EDIT.") g.P("// versions:") - g.P(fmt.Sprintf("// protoc-gen-go-http %s", release)) + g.P(fmt.Sprintf("// - protoc-gen-go-http %s", release)) + g.P("// - protoc ", protocVersion(gen)) + if file.Proto.GetOptions().GetDeprecated() { + g.P("// ", file.Desc.Path(), " is a deprecated file.") + } else { + g.P("// source: ", file.Desc.Path()) + } g.P() g.P("package ", file.GoPackageName) g.P() @@ -301,4 +307,16 @@ func isASCIIDigit(c byte) bool { return '0' <= c && c <= '9' } +func protocVersion(gen *protogen.Plugin) string { + v := gen.Request.GetCompilerVersion() + if v == nil { + return "(unknown)" + } + var suffix string + if s := v.GetSuffix(); s != "" { + suffix = "-" + s + } + return fmt.Sprintf("v%d.%d.%d%s", v.GetMajor(), v.GetMinor(), v.GetPatch(), suffix) +} + const deprecationComment = "// Deprecated: Do not use."