diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-12-08 22:35:02 +0100 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-12-08 22:35:02 +0100 |
commit | c99949535e993c8aab15be7cf6291551d6a2927c (patch) | |
tree | cbde41e68af59bb1ccb2c3744390eb30370de634 | |
parent | afa84ce3089feb19399b8979026515a21c34b6f9 (diff) |
add config ServerGroups accessor
-rw-r--r-- | config.go | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -238,6 +238,22 @@ func (cnf Config) Pools() map[string]map[string]Server { return pools } +// Groups returns all server groups and their member servers. +func (cnf Config) ServerGroups() map[string]map[string]Server { + groups := make(map[string]map[string]Server) + for name, srv := range cnf.Servers { + for _, group := range srv.Groups { + if groups[group] == nil { + groups[group] = make(map[string]Server) + } + + groups[group][name] = srv + } + } + + return groups +} + // RandomGroupServer returns the name of a random member of a server group // or the input string if it is a valid, existent server name. // It also returns a boolean indicating success. |