From a0d06f3a97e09815aa9268d0ee17a22bb56bea49 Mon Sep 17 00:00:00 2001 From: RPRX <63339210+RPRX@users.noreply.github.com> Date: Sun, 26 Mar 2023 10:10:27 +0000 Subject: [PATCH] Add env support to "address", "listen", etc. Usage: `"address": "env:ADDR"`, `"listen": "env:AUDS"`... Just like existing `"port": "env:PORT"` --- infra/conf/common.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/infra/conf/common.go b/infra/conf/common.go index 486e7824..f8f56056 100644 --- a/infra/conf/common.go +++ b/infra/conf/common.go @@ -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 @@ -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)