Merge pull request #89 from Eds-trash-can/main
Server Adding & outsourcing of server into own typemaster
commit
b8725fa08a
60
config.go
60
config.go
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue