Skip to content

Commit

Permalink
fix: Update configuration for improved clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
kianaza committed May 25, 2024
1 parent 38e4f9d commit 33b45b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func Default() Config {
FlushTimeout: 2 * time.Second,
},
Metric: metric.Config{
Address: ":8080",
Server: metric.Server{Address: ":8080"},
Enabled: true,

Check warning on line 34 in internal/config/default.go

View check run for this annotation

Codecov / codecov/patch

internal/config/default.go#L19-L34

Added lines #L19 - L34 were not covered by tests
},
}
Expand Down
6 changes: 5 additions & 1 deletion internal/metric/config.go
Original file line number Diff line number Diff line change
@@ -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"`
}
12 changes: 6 additions & 6 deletions internal/metric/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,30 @@ import (
"go.uber.org/zap"
)

// Server contains information about metrics server.
type Server struct {
// MetricServer contains information about metrics server.
type MetricServer struct {

Check failure on line 13 in internal/metric/server.go

View workflow job for this annotation

GitHub Actions / lint

exported: type name will be used as metric.MetricServer by other packages, and that stutters; consider calling this Server (revive)
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

Check warning on line 20 in internal/metric/server.go

View check run for this annotation

Codecov / codecov/patch

internal/metric/server.go#L19-L20

Added lines #L19 - L20 were not covered by tests

if cfg.Enabled {
srv = http.NewServeMux()
srv.Handle("/metrics", promhttp.Handler())

Check warning on line 24 in internal/metric/server.go

View check run for this annotation

Codecov / codecov/patch

internal/metric/server.go#L22-L24

Added lines #L22 - L24 were not covered by tests
}

return Server{
address: cfg.Address,
return MetricServer{
address: cfg.Server.Address,
srv: srv,

Check warning on line 29 in internal/metric/server.go

View check run for this annotation

Codecov / codecov/patch

internal/metric/server.go#L27-L29

Added lines #L27 - L29 were not covered by tests
}
}

// 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() {

Check warning on line 36 in internal/metric/server.go

View check run for this annotation

Codecov / codecov/patch

internal/metric/server.go#L35-L36

Added lines #L35 - L36 were not covered by tests
// nolint: exhaustruct
srv := http.Server{
Expand Down

0 comments on commit 33b45b9

Please sign in to comment.