mirror of
https://github.com/garethgeorge/backrest.git
synced 2025-12-12 16:55:39 +00:00
19 lines
354 B
Go
19 lines
354 B
Go
package repo
|
|
|
|
import (
|
|
"os"
|
|
"regexp"
|
|
)
|
|
|
|
var (
|
|
envVarSubstRegex = regexp.MustCompile(`\${[^}]*}`)
|
|
)
|
|
|
|
// ExpandEnv expands environment variables of the form ${VAR} in a string.
|
|
func ExpandEnv(s string) string {
|
|
return envVarSubstRegex.ReplaceAllStringFunc(s, func(match string) string {
|
|
e, _ := os.LookupEnv(match[2 : len(match)-1])
|
|
return e
|
|
})
|
|
}
|