[#493] ir: Use pre-allocation in initHTTPServers function

Number of servers to be created is known in advance.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-12 10:37:58 +03:00 committed by Alex Vanin
parent c340d77b74
commit ece6618560

View file

@ -130,15 +130,17 @@ func parsePublicKeysFromString(argument string) (keys.PublicKeys, error) {
}
func initHTTPServers(cfg *viper.Viper) []*httputil.Server {
var httpServers []*httputil.Server
for _, item := range []struct {
items := []struct {
cfgPrefix string
handler func() http.Handler
}{
{"profiler", httputil.Handler},
{"metrics", promhttp.Handler},
} {
}
httpServers := make([]*httputil.Server, 0, len(items))
for _, item := range items {
addr := cfg.GetString(item.cfgPrefix + ".address")
if addr == "" {
continue