Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
demoManito committed Oct 23, 2022
1 parent d4bfc04 commit e8b6609
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions encoding/form/proto_decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,14 @@ func getFieldDescriptor(v protoreflect.Message, fieldName string) protoreflect.F
var fd protoreflect.FieldDescriptor
fd = getDescriptorByFieldAndName(fields, fieldName)
if fd == nil {
reg := regexp.MustCompile(`^\w*\[`)
switch {
case v.Descriptor().FullName() == structMessageFullname:
fd = fields.ByNumber(structFieldsFieldNumber)
case len(fieldName) > 2 && strings.HasSuffix(fieldName, "[]"):
fd = getDescriptorByFieldAndName(fields, strings.TrimSuffix(fieldName, "[]"))
case reg.MatchString(fieldName):
case regexp.MustCompile(`^\w*\[(\w*)]`).MatchString(fieldName):
// If the type is map, you get the string "map[kratos]", where "map" is a field of proto and "kratos" is a key of map
mapName := reg.FindString(fieldName)
fd = getDescriptorByFieldAndName(fields, mapName[:len(mapName)-1])
fd = getDescriptorByFieldAndName(fields, regexp.MustCompile(`^\w*`).FindString(fieldName))
}
}
return fd
Expand Down Expand Up @@ -146,7 +144,6 @@ func populateMapField(fd protoreflect.FieldDescriptor, mp protoreflect.Map, fiel
if err != nil {
return fmt.Errorf("parsing map value %q: %w", fd.FullName().Name(), err)
}
// TODO: map nested map are not supported
mp.Set(key.MapKey(), value)
return nil
}
Expand Down

0 comments on commit e8b6609

Please sign in to comment.