diff --git a/internal/config/default.go b/internal/config/default.go index 2be9f70..c355b06 100644 --- a/internal/config/default.go +++ b/internal/config/default.go @@ -30,7 +30,7 @@ func Default() Config { FlushTimeout: 2 * time.Second, }, Metric: metric.Config{ - Address: ":8080", + Server: metric.Server{Address: ":8080"}, Enabled: true, }, } diff --git a/internal/metric/config.go b/internal/metric/config.go index 9d15d35..a5e3aea 100644 --- a/internal/metric/config.go +++ b/internal/metric/config.go @@ -1,6 +1,10 @@ package metric type Config struct { - Address string `json:"address,omitempty" koanf:"address"` + Server Server `json:"server,omitempty" koanf:"server"` Enabled bool `json:"enabled,omitempty" koanf:"enabled"` } + +type Server struct { + Address string `json:"address,omitempty" koanf:"address"` +} diff --git a/internal/metric/server.go b/internal/metric/server.go index 1844436..d4d8a70 100644 --- a/internal/metric/server.go +++ b/internal/metric/server.go @@ -9,14 +9,14 @@ import ( "go.uber.org/zap" ) -// Server contains information about metrics server. -type Server struct { +// MetricServer contains information about metrics server. +type MetricServer struct { srv *http.ServeMux address string } // NewServer creates a new monitoring server. -func NewServer(cfg Config) Server { +func NewServer(cfg Config) MetricServer { var srv *http.ServeMux if cfg.Enabled { @@ -24,15 +24,15 @@ func NewServer(cfg Config) Server { srv.Handle("/metrics", promhttp.Handler()) } - return Server{ - address: cfg.Address, + return MetricServer{ + address: cfg.Server.Address, srv: srv, } } // Start creates and run a metric server for prometheus in new go routine. // nolint: mnd -func (s Server) Start(logger *zap.Logger) { +func (s MetricServer) Start(logger *zap.Logger) { go func() { // nolint: exhaustruct srv := http.Server{