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)
| 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}. |
| 282 | func 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 | } |
no outgoing calls