Skip to content

Commit a0d06f3

Browse files
RPRXyuhan6665
authored andcommitted
Add env support to "address", "listen", etc.
Usage: `"address": "env:ADDR"`, `"listen": "env:AUDS"`... Just like existing `"port": "env:PORT"`
1 parent 526c678 commit a0d06f3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

infra/conf/common.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ func (v *Address) UnmarshalJSON(data []byte) error {
4545
if err := json.Unmarshal(data, &rawStr); err != nil {
4646
return newError("invalid address: ", string(data)).Base(err)
4747
}
48+
if strings.HasPrefix(rawStr, "env:") {
49+
rawStr = os.Getenv(rawStr[4:])
50+
}
4851
v.Address = net.ParseAddress(rawStr)
4952

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

116119
func parseStringPort(s string) (net.Port, net.Port, error) {
117120
if strings.HasPrefix(s, "env:") {
118-
s = s[4:]
119-
s = os.Getenv(s)
121+
s = os.Getenv(s[4:])
120122
}
121123

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

0 commit comments

Comments
 (0)