added mutable nickname
This commit is contained in:
parent
5527744c43
commit
c78afcdc24
3 changed files with 24 additions and 7 deletions
|
@ -1,7 +1,8 @@
|
||||||
{
|
{
|
||||||
"user": {
|
"user": {
|
||||||
|
"nickname": "serveradmin",
|
||||||
"name": "serveradmin",
|
"name": "serveradmin",
|
||||||
"password": ""
|
"password": "HNxkefVx"
|
||||||
},
|
},
|
||||||
"serverTS": {
|
"serverTS": {
|
||||||
"ip": "127.0.0.1",
|
"ip": "127.0.0.1",
|
||||||
|
|
|
@ -16,6 +16,7 @@ type Config struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
|
Nickname string `json:"nickname"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
}
|
}
|
||||||
|
@ -67,6 +68,7 @@ func (config Config) createFile() error {
|
||||||
func defaults() Config {
|
func defaults() Config {
|
||||||
return Config{
|
return Config{
|
||||||
User: User{
|
User: User{
|
||||||
|
Nickname: "serveradmin",
|
||||||
Name: "serveradmin",
|
Name: "serveradmin",
|
||||||
Password: "",
|
Password: "",
|
||||||
},
|
},
|
||||||
|
@ -82,6 +84,7 @@ func defaults() Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *Config) overrideWithEnv() {
|
func (config *Config) overrideWithEnv() {
|
||||||
|
nickname := os.Getenv("TS3_NICKNAME")
|
||||||
username := os.Getenv("TS3_NAME")
|
username := os.Getenv("TS3_NAME")
|
||||||
password := os.Getenv("TS3_PW")
|
password := os.Getenv("TS3_PW")
|
||||||
tsIP := os.Getenv("TS3_IP")
|
tsIP := os.Getenv("TS3_IP")
|
||||||
|
@ -89,6 +92,10 @@ func (config *Config) overrideWithEnv() {
|
||||||
tsQuery, _ := strconv.Atoi(os.Getenv("TS3_QUERY"))
|
tsQuery, _ := strconv.Atoi(os.Getenv("TS3_QUERY"))
|
||||||
webPort, _ := strconv.Atoi(os.Getenv("WEB_PORT"))
|
webPort, _ := strconv.Atoi(os.Getenv("WEB_PORT"))
|
||||||
|
|
||||||
|
if nickname != "" {
|
||||||
|
config.User.Nickname = nickname
|
||||||
|
}
|
||||||
|
|
||||||
if username != "" {
|
if username != "" {
|
||||||
config.User.Name = username
|
config.User.Name = username
|
||||||
}
|
}
|
||||||
|
@ -101,20 +108,21 @@ func (config *Config) overrideWithEnv() {
|
||||||
config.ServerTS.IP = tsIP
|
config.ServerTS.IP = tsIP
|
||||||
}
|
}
|
||||||
|
|
||||||
if tsPort <= 65535 {
|
if tsPort <= 65535 && tsPort != 0 {
|
||||||
config.ServerTS.PortServer = uint16(tsPort)
|
config.ServerTS.PortServer = uint16(tsPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
if tsQuery <= 65535 {
|
if tsQuery <= 65535 && tsQuery != 0 {
|
||||||
config.ServerTS.PortQuery = uint16(tsQuery)
|
config.ServerTS.PortQuery = uint16(tsQuery)
|
||||||
}
|
}
|
||||||
|
|
||||||
if webPort <= 65535 {
|
if webPort <= 65535 && webPort != 0 {
|
||||||
config.ServerWeb.Port = uint16(webPort)
|
config.ServerWeb.Port = uint16(webPort)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *Config) overrideWithFlags() {
|
func (config *Config) overrideWithFlags() {
|
||||||
|
nickname := flag.String("ts3_nickname", "", "TS3Query nickname")
|
||||||
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")
|
||||||
tsIP := flag.String("ts3_ip", "", "TS3 IP address")
|
tsIP := flag.String("ts3_ip", "", "TS3 IP address")
|
||||||
|
@ -123,6 +131,10 @@ func (config *Config) overrideWithFlags() {
|
||||||
webPort := flag.Uint64("web_port", 65536, "Webserver port")
|
webPort := flag.Uint64("web_port", 65536, "Webserver port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if *nickname != "" {
|
||||||
|
config.User.Nickname = *nickname
|
||||||
|
}
|
||||||
|
|
||||||
if *username != "" {
|
if *username != "" {
|
||||||
config.User.Name = *username
|
config.User.Name = *username
|
||||||
}
|
}
|
||||||
|
@ -135,15 +147,15 @@ func (config *Config) overrideWithFlags() {
|
||||||
config.ServerTS.IP = *tsIP
|
config.ServerTS.IP = *tsIP
|
||||||
}
|
}
|
||||||
|
|
||||||
if *tsPort <= 65535 {
|
if *tsPort <= 65535 && *tsPort != 0 {
|
||||||
config.ServerTS.PortServer = uint16(*tsPort)
|
config.ServerTS.PortServer = uint16(*tsPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *tsQuery <= 65535 {
|
if *tsQuery <= 65535 && *tsQuery != 0 {
|
||||||
config.ServerTS.PortQuery = uint16(*tsQuery)
|
config.ServerTS.PortQuery = uint16(*tsQuery)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *webPort <= 65535 {
|
if *webPort <= 65535 && *webPort != 0 {
|
||||||
config.ServerWeb.Port = uint16(*webPort)
|
config.ServerWeb.Port = uint16(*webPort)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,10 @@ func New(config config.Config) (*Service, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := client.SetNick(config.User.Nickname); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for true {
|
for true {
|
||||||
time.Sleep(time.Second * 150)
|
time.Sleep(time.Second * 150)
|
||||||
|
|
Loading…
Reference in a new issue