Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
72c0527b
Commit
72c0527b
authored
Nov 05, 2015
by
Michael Banzon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for env vars in Caddyfile
This is work in progress for #304
parent
7f7a6aba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
0 deletions
+15
-0
caddy/parse/parsing.go
caddy/parse/parsing.go
+15
-0
No files found.
caddy/parse/parsing.go
View file @
72c0527b
...
...
@@ -4,6 +4,7 @@ import (
"net"
"os"
"path/filepath"
"regexp"
"strings"
)
...
...
@@ -71,6 +72,8 @@ func (p *parser) addresses() error {
for
{
tkn
:=
p
.
Val
()
tkn
=
getValFromEnv
(
tkn
)
// special case: import directive replaces tokens during parse-time
if
tkn
==
"import"
&&
p
.
isNewLine
()
{
err
:=
p
.
doImport
()
...
...
@@ -241,6 +244,7 @@ func (p *parser) directive() error {
}
else
if
p
.
Val
()
==
"}"
&&
nesting
==
0
{
return
p
.
Err
(
"Unexpected '}' because no matching opening brace"
)
}
p
.
tokens
[
p
.
cursor
]
.
text
=
getValFromEnv
(
p
.
tokens
[
p
.
cursor
]
.
text
)
p
.
block
.
Tokens
[
dir
]
=
append
(
p
.
block
.
Tokens
[
dir
],
p
.
tokens
[
p
.
cursor
])
}
...
...
@@ -327,3 +331,14 @@ func (sb serverBlock) HostList() []string {
}
return
sbHosts
}
func
getValFromEnv
(
s
string
)
string
{
re
:=
regexp
.
MustCompile
(
"{
\\
$[^}]+}"
)
envRefs
:=
re
.
FindAllString
(
s
,
-
1
)
for
_
,
ref
:=
range
envRefs
{
s
=
strings
.
Replace
(
s
,
ref
,
os
.
Getenv
(
ref
[
2
:
len
(
ref
)
-
1
]),
-
1
)
}
return
s
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment