forked from Cliffbreak/tsviewer
Merge branch 'master' of https://git.cliffbreak.de/Cliffbreak/tsviewer
This commit is contained in:
commit
0d575286fa
1 changed files with 35 additions and 0 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
@ -48,6 +49,7 @@ func New() (*Config, error) {
|
||||||
jsonParser := json.NewDecoder(configFile)
|
jsonParser := json.NewDecoder(configFile)
|
||||||
jsonParser.Decode(&config)
|
jsonParser.Decode(&config)
|
||||||
|
|
||||||
|
config.overrideWithEnv()
|
||||||
config.overrideWithFlags()
|
config.overrideWithFlags()
|
||||||
|
|
||||||
return &config, nil
|
return &config, nil
|
||||||
|
@ -79,6 +81,39 @@ func defaults() Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (config *Config) overrideWithEnv() {
|
||||||
|
username := os.Getenv("ts3_name")
|
||||||
|
password := os.Getenv("ts3_pw")
|
||||||
|
tsIP := os.Getenv("ts3_ip")
|
||||||
|
tsPort, _ := strconv.Atoi(os.Getenv("ts3_port"))
|
||||||
|
tsQuery, _ := strconv.Atoi(os.Getenv("ts3_query"))
|
||||||
|
webPort, _ := strconv.Atoi(os.Getenv("web_port"))
|
||||||
|
|
||||||
|
if username != "" {
|
||||||
|
config.User.Name = username
|
||||||
|
}
|
||||||
|
|
||||||
|
if password != "" {
|
||||||
|
config.User.Password = password
|
||||||
|
}
|
||||||
|
|
||||||
|
if tsIP != "" {
|
||||||
|
config.ServerTS.IP = tsIP
|
||||||
|
}
|
||||||
|
|
||||||
|
if tsPort <= 65535 {
|
||||||
|
config.ServerTS.PortServer = uint16(tsPort)
|
||||||
|
}
|
||||||
|
|
||||||
|
if tsQuery <= 65535 {
|
||||||
|
config.ServerTS.PortQuery = uint16(tsQuery)
|
||||||
|
}
|
||||||
|
|
||||||
|
if webPort <= 65535 {
|
||||||
|
config.ServerWeb.Port = uint16(webPort)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (config *Config) overrideWithFlags() {
|
func (config *Config) overrideWithFlags() {
|
||||||
username := flag.String("ts3_name", "", "TS3Query username")
|
username := flag.String("ts3_name", "", "TS3Query username")
|
||||||
password := flag.String("ts3_pw", "", "TS3Query user password")
|
password := flag.String("ts3_pw", "", "TS3Query user password")
|
||||||
|
|
Loading…
Reference in a new issue