util/reflect: fix StructFieldByTag
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
4e99680c30
commit
1a1459dd0e
@ -46,9 +46,6 @@ func StructFieldByTag(src interface{}, tkey string, tval string) (interface{}, e
|
||||
if ts, ok := fld.Tag.Lookup(tkey); ok {
|
||||
for _, p := range strings.Split(ts, ",") {
|
||||
if p == tval {
|
||||
if val.Kind() != reflect.Ptr && val.CanAddr() {
|
||||
val = val.Addr()
|
||||
}
|
||||
return val.Interface(), nil
|
||||
}
|
||||
}
|
||||
@ -493,6 +490,7 @@ func btSplitter(str string) []string {
|
||||
}
|
||||
|
||||
// queryToMap turns something like a[b][c]=4 into
|
||||
//
|
||||
// map[string]interface{}{
|
||||
// "a": map[string]interface{}{
|
||||
// "b": map[string]interface{}{
|
||||
|
@ -190,9 +190,9 @@ func TestStructFieldByTag(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if v, ok := iface.(*[]string); !ok {
|
||||
if v, ok := iface.([]string); !ok {
|
||||
t.Fatalf("not *[]string %v", iface)
|
||||
} else if len(*v) != 2 {
|
||||
} else if len(v) != 2 {
|
||||
t.Fatalf("invalid number %v", iface)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user