replaceEnvVars replace env express with env value.
(content string)
| 61 | |
| 62 | // replaceEnvVars replace env express with env value. |
| 63 | func (e ExprVars) replaceEnvVars(content string) string { |
| 64 | content = strings.ReplaceAll(content, "~", os.Getenv("HOME")) |
| 65 | |
| 66 | reg := regexp.MustCompile(`\$ENV\{([^}]+)\}`) |
| 67 | return reg.ReplaceAllStringFunc(content, func(match string) string { |
| 68 | varName := reg.FindStringSubmatch(match)[1] |
| 69 | if value, ok := os.LookupEnv(varName); ok { |
| 70 | return value |
| 71 | } |
| 72 | return match |
| 73 | }) |
| 74 | } |