in utils/json.go [218:257]
func OverrideWithPaths(old interface{}, new interface{}, path string, pathSet map[string]bool) (interface{}, error) {
if len(pathSet) == 0 || old == nil {
return old, nil
}
if _, ok := pathSet[path]; ok {
return new, nil
}
switch oldValue := old.(type) {
case map[string]interface{}:
if newMap, ok := new.(map[string]interface{}); ok {
outMap := make(map[string]interface{})
for key, value := range oldValue {
if newValue, ok := newMap[key]; ok {
nestedPath := strings.TrimPrefix(path+"."+key, ".")
out, err := OverrideWithPaths(value, newValue, nestedPath, pathSet)
if err != nil {
return nil, err
}
outMap[key] = out
} else {
outMap[key] = value
}
}
return outMap, nil
}
case []interface{}:
// Does not support override specific item in list
for v := range pathSet {
if strings.HasPrefix(v, path+".") {
return nil, fmt.Errorf("ignoring specific item in list is not supported")
}
}
if newArr, ok := new.([]interface{}); ok && pathSet[path] {
return mergeArray(oldValue, newArr), nil
}
default:
}
return old, nil
}