From 17c5cb085c8df72c815d7565a2db76d60ba36b90 Mon Sep 17 00:00:00 2001 From: Janos Pasztor Date: Mon, 8 Mar 2021 23:09:21 +0100 Subject: [PATCH] Better validation --- CHANGELOG.md | 4 ++++ server_config.go | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 771cf35..c70dab3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. diff --git a/server_config.go b/server_config.go index 7091872..8fe8a5a 100644 --- a/server_config.go +++ b/server_config.go @@ -1,6 +1,8 @@ package metrics import ( + "fmt" + "github.com/containerssh/http" ) @@ -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() +}