mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-30 22:34:15 -05:00
Environment variables Windows style
Added the Windows style ({%%}) for environment variables in Caddyfiles (for issue #304).
This commit is contained in:
parent
72c0527b7d
commit
01465932e7
1 changed files with 14 additions and 3 deletions
|
@ -8,6 +8,11 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
unixEnvRegEx = regexp.MustCompile("{\\$[^}]+}")
|
||||||
|
windowsEnvRegEx = regexp.MustCompile("{%[^}]+%}")
|
||||||
|
)
|
||||||
|
|
||||||
type parser struct {
|
type parser struct {
|
||||||
Dispenser
|
Dispenser
|
||||||
block serverBlock // current server block being parsed
|
block serverBlock // current server block being parsed
|
||||||
|
@ -333,12 +338,18 @@ func (sb serverBlock) HostList() []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getValFromEnv(s string) string {
|
func getValFromEnv(s string) string {
|
||||||
re := regexp.MustCompile("{\\$[^}]+}")
|
envRefsUnix := unixEnvRegEx.FindAllString(s, -1)
|
||||||
envRefs := re.FindAllString(s, -1)
|
|
||||||
|
|
||||||
for _, ref := range envRefs {
|
for _, ref := range envRefsUnix {
|
||||||
s = strings.Replace(s, ref, os.Getenv(ref[2:len(ref)-1]), -1)
|
s = strings.Replace(s, ref, os.Getenv(ref[2:len(ref)-1]), -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
envRefsWin := unixEnvRegEx.FindAllString(s, -1)
|
||||||
|
|
||||||
|
for _, ref := range envRefsWin {
|
||||||
|
s = strings.Replace(s, ref, os.Getenv(ref[2:len(ref)-2]), -1)
|
||||||
|
}
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue