MCPcopy Create free account
hub / github.com/cortexproject/cortex / expandEnv

Function expandEnv

cmd/cortex/main.go:282–293  ·  view source on GitHub ↗

expandEnv replaces ${var} or $var in config according to the values of the current environment variables. The replacement is case-sensitive. References to undefined variables are replaced by the empty string. A default value can be given by using the form ${var:default value}.

(config []byte)

Source from the content-addressed store, hash-verified

280// The replacement is case-sensitive. References to undefined variables are replaced by the empty string.
281// A default value can be given by using the form ${var:default value}.
282func expandEnv(config []byte) []byte {
283 return []byte(os.Expand(string(config), func(key string) string {
284 keyAndDefault := strings.SplitN(key, ":", 2)
285 key = keyAndDefault[0]
286
287 v := os.Getenv(key)
288 if v == "" && len(keyAndDefault) == 2 {
289 v = keyAndDefault[1] // Set value to the default.
290 }
291 return v
292 }))
293}

Callers 2

TestExpandEnvFunction · 0.85
LoadConfigFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestExpandEnvFunction · 0.68