From c340d77b7484dac3086ea09732562ef449861872 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 12 May 2021 10:35:18 +0300 Subject: [PATCH] [#493] ir: Replace creation of HTTP servers into a separate function Signed-off-by: Leonard Lyubich --- cmd/neofs-ir/main.go | 61 ++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/cmd/neofs-ir/main.go b/cmd/neofs-ir/main.go index 62de3e0c..c1a262fd 100644 --- a/cmd/neofs-ir/main.go +++ b/cmd/neofs-ir/main.go @@ -14,6 +14,7 @@ import ( httputil "github.com/nspcc-dev/neofs-node/pkg/util/http" "github.com/nspcc-dev/neofs-node/pkg/util/logger" "github.com/prometheus/client_golang/prometheus/promhttp" + "github.com/spf13/viper" "go.uber.org/zap" ) @@ -59,33 +60,7 @@ func main() { ctx := grace.NewGracefulContext(log) intErr := make(chan error) // internal inner ring errors - var httpServers []*httputil.Server - - for _, item := range []struct { - cfgPrefix string - handler func() http.Handler - }{ - {"profiler", httputil.Handler}, - {"metrics", promhttp.Handler}, - } { - addr := cfg.GetString(item.cfgPrefix + ".address") - if addr == "" { - continue - } - - var prm httputil.Prm - - prm.Address = addr - prm.Handler = item.handler() - - httpServers = append(httpServers, - httputil.New(prm, - httputil.WithShutdownTimeout( - cfg.GetDuration(item.cfgPrefix+".shutdown_timeout"), - ), - ), - ) - } + httpServers := initHTTPServers(cfg) innerRing, err := innerring.New(ctx, log, cfg) if err != nil { @@ -153,3 +128,35 @@ func parsePublicKeysFromString(argument string) (keys.PublicKeys, error) { return innerring.ParsePublicKeysFromStrings(publicKeysString) } + +func initHTTPServers(cfg *viper.Viper) []*httputil.Server { + var httpServers []*httputil.Server + + for _, item := range []struct { + cfgPrefix string + handler func() http.Handler + }{ + {"profiler", httputil.Handler}, + {"metrics", promhttp.Handler}, + } { + addr := cfg.GetString(item.cfgPrefix + ".address") + if addr == "" { + continue + } + + var prm httputil.Prm + + prm.Address = addr + prm.Handler = item.handler() + + httpServers = append(httpServers, + httputil.New(prm, + httputil.WithShutdownTimeout( + cfg.GetDuration(item.cfgPrefix+".shutdown_timeout"), + ), + ), + ) + } + + return httpServers +}