MCPcopy Create free account
hub / github.com/devspace-sh/devspace / doWalk

Function doWalk

pkg/devspace/deploy/deployer/kubectl/walk/walk.go:24–72  ·  view source on GitHub ↗
(path string, d interface{}, match MatchFn, replace ReplaceFn)

Source from the content-addressed store, hash-verified

22}
23
24func doWalk(path string, d interface{}, match MatchFn, replace ReplaceFn) error {
25 var err error
26
27 switch t := d.(type) {
28 case []interface{}:
29 for idx, val := range t {
30 newPath := path + "/" + strconv.Itoa(idx)
31 value, ok := val.(string)
32 if !ok {
33 err = doWalk(newPath, val, match, replace)
34 if err != nil {
35 return err
36 }
37
38 continue
39 }
40
41 if match(fmt.Sprintf("[%d]", idx), value) {
42 t[idx], err = replace(newPath, value)
43 if err != nil {
44 return err
45 }
46 }
47 }
48 case map[string]interface{}:
49 for k, v := range t {
50 key := k
51 newPath := path + "/" + key
52 value, ok := v.(string)
53 if !ok {
54 err = doWalk(newPath, v, match, replace)
55 if err != nil {
56 return err
57 }
58
59 continue
60 }
61
62 if match(key, value) {
63 t[k], err = replace(newPath, value)
64 if err != nil {
65 return err
66 }
67 }
68 }
69 }
70
71 return nil
72}

Callers 2

WalkFunction · 0.85
WalkStringMapFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected