File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -41,7 +41,23 @@ func deepGetImpl(v reflect.Value, path []string) interface{} {
41
41
case reflect .Struct :
42
42
return deepGetImpl (v .FieldByName (path [0 ]), path [1 :])
43
43
case reflect .Map :
44
- return deepGetImpl (v .MapIndex (reflect .ValueOf (path [0 ])), path [1 :])
44
+ // If the first part of the path is a key in the map, we use it directly
45
+ if mapValue := v .MapIndex (reflect .ValueOf (path [0 ])); mapValue .IsValid () {
46
+ return deepGetImpl (mapValue , path [1 :])
47
+ }
48
+
49
+ // If the first part of the path is not a key in the map, we try to find a valid key by joining the path parts
50
+ for i := 2 ; i <= len (path ); i ++ {
51
+ joinedPath := strings .Join (path [0 :i ], "." )
52
+ if mapValue := v .MapIndex (reflect .ValueOf (joinedPath )); mapValue .IsValid () {
53
+ if i == len (path ) {
54
+ return mapValue .Interface ()
55
+ }
56
+ return deepGetImpl (mapValue , path [i :])
57
+ }
58
+ }
59
+
60
+ return nil
45
61
case reflect .Slice , reflect .Array :
46
62
i , err := parseAllocateInt (path [0 ])
47
63
if err != nil {
You can’t perform that action at this time.
0 commit comments