mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-17 21:07:54 +02:00
http get方法 url 参数带中括号 (#1226)
* fix url query array problem * use TrimSuffix
This commit is contained in:
parent
77d2cfb653
commit
d4ac341bc8
@ -36,9 +36,10 @@ func populateFieldValues(v protoreflect.Message, fieldPath []string, values []st
|
||||
var fd protoreflect.FieldDescriptor
|
||||
for i, fieldName := range fieldPath {
|
||||
fields := v.Descriptor().Fields()
|
||||
|
||||
if fd = fields.ByName(protoreflect.Name(fieldName)); fd == nil {
|
||||
fd = fields.ByJSONName(fieldName)
|
||||
if fd = getDescriptorByFieldAndName(fields, fieldName); fd == nil {
|
||||
if len(fieldName) > 2 && strings.HasSuffix(fieldName, "[]") {
|
||||
fd = getDescriptorByFieldAndName(fields, strings.TrimSuffix(fieldName, "[]"))
|
||||
}
|
||||
if fd == nil {
|
||||
// ignore unexpected field.
|
||||
return nil
|
||||
@ -72,6 +73,17 @@ func populateFieldValues(v protoreflect.Message, fieldPath []string, values []st
|
||||
return populateField(fd, v, values[0])
|
||||
}
|
||||
|
||||
func getDescriptorByFieldAndName(fields protoreflect.FieldDescriptors, fieldName string) protoreflect.FieldDescriptor {
|
||||
var fd protoreflect.FieldDescriptor
|
||||
if fd = fields.ByName(protoreflect.Name(fieldName)); fd == nil {
|
||||
fd = fields.ByJSONName(fieldName)
|
||||
if fd == nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fd
|
||||
}
|
||||
|
||||
func populateField(fd protoreflect.FieldDescriptor, v protoreflect.Message, value string) error {
|
||||
val, err := parseField(fd, value)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user