Commit 01465932 authored by Michael Banzon's avatar Michael Banzon

Environment variables Windows style

Added the Windows style ({%%}) for environment variables in Caddyfiles
(for issue #304).
parent 72c0527b
...@@ -8,6 +8,11 @@ import ( ...@@ -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 { ...@@ -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
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment