Interpolate replaces variables in a string with the values from a mapping
(config map[string]any, opts Options)
| 32 | |
| 33 | // Interpolate replaces variables in a string with the values from a mapping |
| 34 | func 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 | |
| 58 | func recursiveInterpolate(value any, path Path, opts Options) (any, error) { |
| 59 | switch value := value.(type) { |
searching dependent graphs…