Skip to content

Commit

Permalink
Add env support to "address", "listen", etc.
Browse files Browse the repository at this point in the history
Usage: `"address": "env:ADDR"`, `"listen": "env:AUDS"`...
Just like existing `"port": "env:PORT"`
  • Loading branch information
RPRX authored Mar 26, 2023
1 parent 1cf5bef commit 30c2003
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions infra/conf/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func (v *Address) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, &rawStr); err != nil {
return newError("invalid address: ", string(data)).Base(err)
}
if strings.HasPrefix(rawStr, "env:") {
rawStr = os.Getenv(rawStr[4:])
}
v.Address = net.ParseAddress(rawStr)

return nil
Expand Down Expand Up @@ -115,8 +118,7 @@ func parseIntPort(data []byte) (net.Port, error) {

func parseStringPort(s string) (net.Port, net.Port, error) {
if strings.HasPrefix(s, "env:") {
s = s[4:]
s = os.Getenv(s)
s = os.Getenv(s[4:])
}

pair := strings.SplitN(s, "-", 2)
Expand Down

0 comments on commit 30c2003

Please sign in to comment.