mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -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"
|
||||
)
|
||||
|
||||
var (
|
||||
unixEnvRegEx = regexp.MustCompile("{\\$[^}]+}")
|
||||
windowsEnvRegEx = regexp.MustCompile("{%[^}]+%}")
|
||||
)
|
||||
|
||||
type parser struct {
|
||||
Dispenser
|
||||
block serverBlock // current server block being parsed
|
||||
|
@ -333,12 +338,18 @@ func (sb serverBlock) HostList() []string {
|
|||
}
|
||||
|
||||
func getValFromEnv(s string) string {
|
||||
re := regexp.MustCompile("{\\$[^}]+}")
|
||||
envRefs := re.FindAllString(s, -1)
|
||||
envRefsUnix := unixEnvRegEx.FindAllString(s, -1)
|
||||
|
||||
for _, ref := range envRefs {
|
||||
for _, ref := range envRefsUnix {
|
||||
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
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue