Skip to content

Commit c807621

Browse files
szyhfantonmedv
authored andcommitted
Add support for method of map.
1 parent 3c8fc57 commit c807621

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

runtime.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ func getFunc(val interface{}, i interface{}) (interface{}, bool) {
9696
if value.IsValid() && value.CanInterface() {
9797
return value.Interface(), true
9898
}
99+
// A map may have method too.
100+
if v.NumMethod() > 0 {
101+
name := reflect.ValueOf(i).String()
102+
method := v.MethodByName(name)
103+
if method.IsValid() && method.CanInterface() {
104+
return method.Interface(), true
105+
}
106+
}
99107
case reflect.Struct:
100108
name := reflect.ValueOf(i).String()
101109
method := v.MethodByName(name)

0 commit comments

Comments
 (0)