[#493] ir: Replace creation of HTTP servers into a separate function
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
8d17dab86e
commit
c340d77b74
1 changed files with 34 additions and 27 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue