1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-02-19 19:10:08 +02:00

fix(cmd/proto-gen-http): fix the problem that the field declaration does not exist causing panic (#1553)

This commit is contained in:
包子 2021-10-15 17:18:13 +08:00 committed by GitHub
parent 979ec39c53
commit 014778b72a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -161,6 +161,10 @@ func buildMethodDesc(g *protogen.GeneratedFile, m *protogen.Method, method, path
fields := m.Input.Desc.Fields()
for _, v := range vars {
fd := fields.ByName(protoreflect.Name(v))
if fd == nil {
fmt.Fprintf(os.Stderr, "\u001B[31mERROR\u001B[m: The corresponding field '%s' declaration in message could not be found in '%s'\n", v, path)
os.Exit(2)
}
if fd.IsMap() {
fmt.Fprintf(os.Stderr, "\u001B[31mWARN\u001B[m: The field in path:'%s' shouldn't be a map.\n", v)
}