Use environment variable in frontend

This commit is contained in:
Lan Tian 2019-01-23 20:36:06 +08:00
parent a79b0cd92c
commit eb977532c0
No known key found for this signature in database
GPG Key ID: 27F31700E751EC22

View File

@ -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()
}