Skip to content

Commit

Permalink
add config ServerGroups accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
HimbeerserverDE committed Dec 8, 2023
1 parent afa84ce commit c999495
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c999495

Please sign in to comment.