Export and use DefaultSrvInfo method

master
HimbeerserverDE 2022-05-02 22:01:18 +02:00
parent ce203b8f18
commit 66498fe02b
No known key found for this signature in database
GPG Key ID: A3D3E205DA0B0401
2 changed files with 9 additions and 8 deletions

View File

@ -162,7 +162,10 @@ func RmServer(name string) bool {
return true
}
func (cnf Config) defaultSrvInfo() (string, Server) {
// DefaultSrvInfo returns both the name of the default server
// and information about it. The return values are uninitialized
// if no servers exist.
func (cnf Config) DefaultSrvInfo() (string, Server) {
for name, srv := range Conf().Servers {
return name, srv
}
@ -174,16 +177,16 @@ func (cnf Config) defaultSrvInfo() (string, Server) {
// DefaultSrvName returns the name of the default server.
// If no servers exist it returns an empty string.
func (cnf Config) DefaultSrvName() string {
name, _ := cnf.defaultSrvInfo()
name, _ := cnf.DefaultSrvInfo()
return name
}
// DefaultSrv returns information about the default server.
// If no servers exist the returned struct will be uninitialized.
// This is a faster shortcut for Config.Servers[Config.DefaultSrvName].
// You should thus only use this method.
// You should thus only use this method or the DefaultSrvInfo method.
func (cnf Config) DefaultSrv() Server {
_, srv := cnf.defaultSrvInfo()
_, srv := cnf.DefaultSrvInfo()
return srv
}

6
run.go
View File

@ -107,15 +107,13 @@ func runFunc() {
return
}
srv := conf.DefaultSrv()
srvName := conf.DefaultSrvName()
srvName, srv := conf.DefaultSrvInfo()
lastSrv, err := authIface.LastSrv(cc.Name())
if err == nil && !Conf().ForceDefaultSrv && lastSrv != srvName {
for name, s := range conf.Servers {
if name == lastSrv {
srv = s
srvName = name
srv = s
break
}