Skip to content
This repository has been archived by the owner on Oct 2, 2022. It is now read-only.

Commit

Permalink
Better validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Janos Pasztor committed Mar 8, 2021
1 parent bb4798c commit 17c5cb0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.9.7: Better validation

This release adds better validation for the metrics server.

## 0.9.6: Fixed listen default

This release fixes a regression where the default `listen` value would be `0.0.0.0:8080` instead of `0.0.0.0:9100`.
Expand Down
13 changes: 13 additions & 0 deletions server_config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package metrics

import (
"fmt"

"github.com/containerssh/http"
)

Expand All @@ -10,3 +12,14 @@ type Config struct {
Enable bool `yaml:"enable" json:"enable" comment:"Enable metrics server." default:"false"`
Path string `yaml:"path" json:"path" comment:"Path to run the Metrics endpoint on." default:"/metrics"`
}

// Validate validates the configuration.
func (c Config) Validate() error {
if !c.Enable {
return nil
}
if c.Path == "" {
return fmt.Errorf("metrics path cannot be empty")
}
return c.ServerConfiguration.Validate()
}

0 comments on commit 17c5cb0

Please sign in to comment.