mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-17 21:07:54 +02:00
feat: add protoc-gen-go-http annotations synchronization with protoc-gen-go-grpc (#2151)
This commit is contained in:
parent
035c2f5387
commit
addcbba66e
@ -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."
|
||||
|
Loading…
x
Reference in New Issue
Block a user