From c99949535e993c8aab15be7cf6291551d6a2927c Mon Sep 17 00:00:00 2001 From: HimbeerserverDE Date: Fri, 8 Dec 2023 22:35:02 +0100 Subject: [PATCH] add config ServerGroups accessor --- config.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/config.go b/config.go index d270f77..ed42084 100644 --- a/config.go +++ b/config.go @@ -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.