mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-30 02:43:01 +00:00
Add env support to "address", "listen", etc.
Usage: `"address": "env:ADDR"`, `"listen": "env:AUDS"`... Just like existing `"port": "env:PORT"`
This commit is contained in:
parent
526c6789ed
commit
a0d06f3a97
@ -45,6 +45,9 @@ func (v *Address) UnmarshalJSON(data []byte) error {
|
|||||||
if err := json.Unmarshal(data, &rawStr); err != nil {
|
if err := json.Unmarshal(data, &rawStr); err != nil {
|
||||||
return newError("invalid address: ", string(data)).Base(err)
|
return newError("invalid address: ", string(data)).Base(err)
|
||||||
}
|
}
|
||||||
|
if strings.HasPrefix(rawStr, "env:") {
|
||||||
|
rawStr = os.Getenv(rawStr[4:])
|
||||||
|
}
|
||||||
v.Address = net.ParseAddress(rawStr)
|
v.Address = net.ParseAddress(rawStr)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -115,8 +118,7 @@ func parseIntPort(data []byte) (net.Port, error) {
|
|||||||
|
|
||||||
func parseStringPort(s string) (net.Port, net.Port, error) {
|
func parseStringPort(s string) (net.Port, net.Port, error) {
|
||||||
if strings.HasPrefix(s, "env:") {
|
if strings.HasPrefix(s, "env:") {
|
||||||
s = s[4:]
|
s = os.Getenv(s[4:])
|
||||||
s = os.Getenv(s)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pair := strings.SplitN(s, "-", 2)
|
pair := strings.SplitN(s, "-", 2)
|
||||||
|
Loading…
Reference in New Issue
Block a user