From eb977532c0ead57056c8a04fc6edcd26fbea2a63 Mon Sep 17 00:00:00 2001 From: Lan Tian Date: Wed, 23 Jan 2019 20:36:06 +0800 Subject: [PATCH] Use environment variable in frontend --- frontend/main.go | 49 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/frontend/main.go b/frontend/main.go index 3382169..fc25adf 100644 --- a/frontend/main.go +++ b/frontend/main.go @@ -1,8 +1,10 @@ package main import ( + "os" "flag" "strings" + "strconv" ) var settingServers []string @@ -12,17 +14,50 @@ var settingWhoisServer string var settingListen string func main() { - serversPtr := flag.String("servers", "", "server name prefixes, separated by comma") - domainPtr := flag.String("domain", "", "server name domain suffixes") - portPtr := flag.Int("port", 8000, "port bird-lgproxy is running on") - whoisPtr := flag.String("whois", "whois.verisign-grs.com", "whois server for queries") - listenPortPtr := flag.String("listen", ":5000", "address bird-lg is listening on") + serversDefault := "" + domainDefault := "" + proxyPortDefault := 8000 + whoisDefault := "whois.verisign-grs.com" + listenDefault := ":5000" + + if serversEnv := os.Getenv("BIRDLG_SERVERS"); serversEnv != "" { + serversDefault = serversEnv + } + if domainEnv := os.Getenv("BIRDLG_DOMAIN"); domainEnv != "" { + domainDefault = domainEnv + } + if proxyPortEnv := os.Getenv("BIRDLG_PROXY_PORT"); proxyPortEnv != "" { + var err error + proxyPortDefault, err = strconv.Atoi(proxyPortEnv) + if err != nil{ + panic(err) + } + } + if whoisEnv := os.Getenv("BIRDLG_WHOIS"); whoisEnv != "" { + whoisDefault = whoisEnv + } + if listenEnv := os.Getenv("BIRDLG_LISTEN"); listenEnv != "" { + listenDefault = listenEnv + } + + serversPtr := flag.String("servers", serversDefault, "server name prefixes, separated by comma") + domainPtr := flag.String("domain", domainDefault, "server name domain suffixes") + proxyPortPtr := flag.Int("proxy-port", proxyPortDefault, "port bird-lgproxy is running on") + whoisPtr := flag.String("whois", whoisDefault, "whois server for queries") + listenPtr := flag.String("listen", listenDefault, "address bird-lg is listening on") flag.Parse() + if *serversPtr == "" { + panic("no server set") + } else if *domainPtr == "" { + panic("no base domain set") + } + settingServers = strings.Split(*serversPtr, ",") settingServersDomain = *domainPtr - settingServersPort = *portPtr + settingServersPort = *proxyPortPtr settingWhoisServer = *whoisPtr - settingListen = *listenPortPtr + settingListen = *listenPtr + webServerStart() }