Merge pull request #89 from Eds-trash-can/main

Server Adding & outsourcing of server into own type
master
HimbeerserverDE 2022-04-21 23:06:02 +02:00 committed by GitHub
commit b8725fa08a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 46 additions and 14 deletions

View File

@ -22,23 +22,25 @@ var configMu sync.RWMutex
var loadConfigOnce sync.Once
type Server struct {
Name string
Addr string
Fallbacks []string
}
// A Config contains information from the configuration file
// that affects the way the proxy works.
type Config struct {
NoPlugins bool
CmdPrefix string
RequirePasswd bool
SendInterval float32
UserLimit int
AuthBackend string
NoTelnet bool
TelnetAddr string
BindAddr string
Servers []struct {
Name string
Addr string
Fallbacks []string
}
NoPlugins bool
CmdPrefix string
RequirePasswd bool
SendInterval float32
UserLimit int
AuthBackend string
NoTelnet bool
TelnetAddr string
BindAddr string
Servers []Server
ForceDefaultSrv bool
FallbackServers []string
CSMRF struct {
@ -85,6 +87,36 @@ func Conf() Config {
return config
}
// AddServer appends a server to the list of configured servers.
func AddServer(server Server) bool {
configMu.Lock()
defer configMu.Unlock()
for _, srv := range config.Servers {
if srv.Name == server.Name {
return false
}
}
config.Servers = append(config.Servers, server)
return true
}
// DelServer removes a server based on name.
func DelServer(name string) bool {
configMu.Lock()
defer configMu.Unlock()
for i, srv := range config.Servers {
if srv.Name == name {
config.Servers = append(config.Servers[:i], config.Servers[1+i:]...)
return true
}
}
return false
}
// FallbackServers returns a slice of server names that
// a server can fall back to.
func FallbackServers(server string) []string {