add additional wrappers support
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
f42994e5c0
commit
147c2d756e
37
util.go
37
util.go
@ -147,11 +147,11 @@ func newPathRequest(path string, method string, body string, msg interface{}, ta
|
||||
switch val.Type().Kind() {
|
||||
case reflect.Slice:
|
||||
for idx := 0; idx < val.Len(); idx++ {
|
||||
values.Add(t.name, fmt.Sprintf("%v", val.Index(idx).Interface()))
|
||||
values.Add(t.name, getParam(val.Index(idx)))
|
||||
}
|
||||
fieldsmapskip[t.name] = struct{}{}
|
||||
default:
|
||||
fieldsmap[t.name] = fmt.Sprintf("%v", val.Interface())
|
||||
fieldsmap[t.name] = getParam(val)
|
||||
}
|
||||
} else if (body == "*" || body == t.name) && method != http.MethodGet {
|
||||
if tnmsg.Field(i).CanSet() {
|
||||
@ -160,10 +160,10 @@ func newPathRequest(path string, method string, body string, msg interface{}, ta
|
||||
} else {
|
||||
if val.Type().Kind() == reflect.Slice {
|
||||
for idx := 0; idx < val.Len(); idx++ {
|
||||
values.Add(t.name, fmt.Sprintf("%v", val.Index(idx).Interface()))
|
||||
values.Add(t.name, getParam(val.Index(idx)))
|
||||
}
|
||||
} else {
|
||||
values.Add(t.name, fmt.Sprintf("%v", val.Interface()))
|
||||
values.Add(t.name, getParam(val))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -216,12 +216,6 @@ func newPathRequest(path string, method string, body string, msg interface{}, ta
|
||||
_, _ = b.WriteString(values.Encode())
|
||||
}
|
||||
|
||||
/*
|
||||
if err = rutil.ZeroFieldByPath(nmsg, k); err != nil {
|
||||
return nil, errors.BadRequest("go.micro.client", err.Error())
|
||||
}
|
||||
*/
|
||||
|
||||
if rutil.IsZero(nmsg) {
|
||||
return b.String(), nil, nil
|
||||
}
|
||||
@ -324,3 +318,26 @@ type tag struct {
|
||||
key string
|
||||
name string
|
||||
}
|
||||
|
||||
func getParam(val reflect.Value) string {
|
||||
var v string
|
||||
switch val.Kind() {
|
||||
case reflect.Ptr:
|
||||
switch reflect.Indirect(val).Type().String() {
|
||||
case
|
||||
"wrapperspb.BoolValue",
|
||||
"wrapperspb.BytesValue",
|
||||
"wrapperspb.DoubleValue",
|
||||
"wrapperspb.FloatValue",
|
||||
"wrapperspb.Int32Value", "wrapperspb.Int64Value",
|
||||
"wrapperspb.StringValue",
|
||||
"wrapperspb.UInt32Value", "wrapperspb.UInt64Value":
|
||||
if eva := reflect.Indirect(val).FieldByName("Value"); eva.IsValid() {
|
||||
v = getParam(eva)
|
||||
}
|
||||
}
|
||||
default:
|
||||
v = fmt.Sprintf("%v", val.Interface())
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user