From 01c26985b161c66aa230ea537549eda57a1360ad Mon Sep 17 00:00:00 2001 From: Riley Date: Sun, 1 May 2022 10:14:27 +0200 Subject: texturePools! --- config.go | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'config.go') diff --git a/config.go b/config.go index 3b4a6ba..25319ad 100644 --- a/config.go +++ b/config.go @@ -23,9 +23,10 @@ var configMu sync.RWMutex var loadConfigOnce sync.Once type Server struct { - Name string - Addr string - Fallbacks []string + Name string + Addr string + TexturePool string + Fallbacks []string } // A Config contains information from the configuration file @@ -87,6 +88,32 @@ func Conf() Config { return config } +// UniquePoolServers returns a []server where each Pool is only +// represented once +func UniquePoolServers() []Server { + var srvs []Server + conf := Conf() + + for _, srv := range conf.Servers { + if len(srv.TexturePool) == 0 { + srv.TexturePool = srv.Name + } + } + +AddLoop: + for _, srv := range conf.Servers { + for _, srv2 := range srvs { + if srv.TexturePool == srv2.TexturePool { + continue AddLoop + } + } + + srvs = append(srvs, srv) + } + + return srvs +} + // AddServer appends a server to the list of configured servers. func AddServer(server Server) bool { configMu.Lock() -- cgit v1.2.3 From b8fb482ff925aa004527cf246eb985a9d0017d58 Mon Sep 17 00:00:00 2001 From: HimbeerserverDE Date: Sun, 1 May 2022 16:33:37 +0200 Subject: Fix UniquePoolServers behavior and quality --- config.go | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'config.go') diff --git a/config.go b/config.go index 8ae75d9..cfcf9ee 100644 --- a/config.go +++ b/config.go @@ -24,10 +24,10 @@ var configMu sync.RWMutex var loadConfigOnce sync.Once type Server struct { - Name string - Addr string + Name string + Addr string TexturePool string - Fallbacks []string + Fallbacks []string dynamic bool } @@ -91,23 +91,17 @@ func Conf() Config { return config } -// UniquePoolServers returns a []server where each Pool is only -// represented once +// UniquePoolServers returns a []Server where each +// TexturePool is only represented once. func UniquePoolServers() []Server { var srvs []Server conf := Conf() +AppendLoop: for _, srv := range conf.Servers { - if len(srv.TexturePool) == 0 { - srv.TexturePool = srv.Name - } - } - -AddLoop: - for _, srv := range conf.Servers { - for _, srv2 := range srvs { - if srv.TexturePool == srv2.TexturePool { - continue AddLoop + for _, s := range srvs { + if srv.TexturePool == s.TexturePool { + continue AppendLoop } } @@ -255,13 +249,17 @@ DynLoop: } } - for _, srv := range config.Servers { + for i, srv := range config.Servers { for _, s := range config.Servers { if srv.Name == s.Name { config = oldConf return fmt.Errorf("duplicate server %s", s.Name) } } + + if srv.TexturePool == "" { + config.Servers[i].TexturePool = srv.Name + } } log.Print("load config") -- cgit v1.2.3