MCPcopy Index your code
hub / github.com/docker/cli / recursiveInterpolate

Function recursiveInterpolate

cli/compose/interpolation/interpolation.go:58–100  ·  view source on GitHub ↗
(value any, path Path, opts Options)

Source from the content-addressed store, hash-verified

56}
57
58func recursiveInterpolate(value any, path Path, opts Options) (any, error) {
59 switch value := value.(type) {
60 case string:
61 newValue, err := opts.Substitute(value, template.Mapping(opts.LookupValue))
62 if err != nil || newValue == value {
63 return value, newPathError(path, err)
64 }
65 caster, ok := opts.getCasterForPath(path)
66 if !ok {
67 return newValue, nil
68 }
69 casted, err := caster(newValue)
70 if err != nil {
71 return casted, newPathError(path, fmt.Errorf("failed to cast to expected type: %w", err))
72 }
73 return casted, nil
74
75 case map[string]any:
76 out := map[string]any{}
77 for key, elem := range value {
78 interpolatedElem, err := recursiveInterpolate(elem, path.Next(key), opts)
79 if err != nil {
80 return nil, err
81 }
82 out[key] = interpolatedElem
83 }
84 return out, nil
85
86 case []any:
87 out := make([]any, len(value))
88 for i, elem := range value {
89 interpolatedElem, err := recursiveInterpolate(elem, path.Next(PathMatchList), opts)
90 if err != nil {
91 return nil, err
92 }
93 out[i] = interpolatedElem
94 }
95 return out, nil
96
97 default:
98 return value, nil
99 }
100}
101
102func newPathError(path Path, err error) error {
103 switch err := err.(type) {

Callers 1

InterpolateFunction · 0.85

Calls 3

newPathErrorFunction · 0.85
getCasterForPathMethod · 0.80
NextMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…