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

Function Interpolate

cli/compose/interpolation/interpolation.go:34–56  ·  view source on GitHub ↗

Interpolate replaces variables in a string with the values from a mapping

(config map[string]any, opts Options)

Source from the content-addressed store, hash-verified

32
33// Interpolate replaces variables in a string with the values from a mapping
34func Interpolate(config map[string]any, opts Options) (map[string]any, error) {
35 if opts.LookupValue == nil {
36 opts.LookupValue = os.LookupEnv
37 }
38 if opts.TypeCastMapping == nil {
39 opts.TypeCastMapping = make(map[Path]Cast)
40 }
41 if opts.Substitute == nil {
42 opts.Substitute = template.Substitute
43 }
44
45 out := map[string]any{}
46
47 for key, value := range config {
48 interpolatedValue, err := recursiveInterpolate(value, NewPath(key), opts)
49 if err != nil {
50 return out, err
51 }
52 out[key] = interpolatedValue
53 }
54
55 return out, nil
56}
57
58func recursiveInterpolate(value any, path Path, opts Options) (any, error) {
59 switch value := value.(type) {

Callers 4

TestInterpolateFunction · 0.85
TestInvalidInterpolationFunction · 0.85
TestInterpolateWithCastFunction · 0.85

Calls 2

recursiveInterpolateFunction · 0.85
NewPathFunction · 0.85

Tested by 4

TestInterpolateFunction · 0.68
TestInvalidInterpolationFunction · 0.68
TestInterpolateWithCastFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…