1
0
mirror of https://github.com/go-kratos/kratos.git synced 2026-05-22 10:15:24 +02:00

feat:add warning when http path filed use map or list (#1526)

* feat:add warning when http path filed use map or list
This commit is contained in:
海雨
2021-09-30 14:12:27 +08:00
committed by GitHub
parent a2f53128cf
commit 23a96a3d63
+14 -1
View File
@@ -5,6 +5,8 @@ import (
"os"
"strings"
"google.golang.org/protobuf/reflect/protoreflect"
"github.com/go-kratos/kratos/v2"
"google.golang.org/genproto/googleapis/api/annotations"
"google.golang.org/protobuf/compiler/protogen"
@@ -155,6 +157,17 @@ func buildHTTPRule(g *protogen.GeneratedFile, m *protogen.Method, rule *annotati
func buildMethodDesc(g *protogen.GeneratedFile, m *protogen.Method, method, path string) *methodDesc {
defer func() { methodSets[m.GoName]++ }()
vars := buildPathVars(m, path)
fields := m.Input.Desc.Fields()
for _, v := range vars {
fd := fields.ByName(protoreflect.Name(v))
if fd.IsMap() {
fmt.Fprintf(os.Stderr, "\u001B[31mWARN\u001B[m: The field in path:'%s' shouldn't be a map.\n", v)
}
if fd.IsList() {
fmt.Fprintf(os.Stderr, "\u001B[31mWARN\u001B[m: The field in path:'%s' shouldn't be a list.\n", v)
}
}
return &methodDesc{
Name: m.GoName,
Num: methodSets[m.GoName],
@@ -162,7 +175,7 @@ func buildMethodDesc(g *protogen.GeneratedFile, m *protogen.Method, method, path
Reply: g.QualifiedGoIdent(m.Output.GoIdent),
Path: path,
Method: method,
HasVars: len(buildPathVars(m, path)) > 0,
HasVars: len(vars) > 0,
}
}