From 13195d209c523d3d45f3456086bce61223950dab Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 8 Apr 2021 17:57:55 +0200 Subject: Fixed wrong implementation of yaml default values and of the corresponding tests --- pkg/config/config.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'pkg/config/config.go') diff --git a/pkg/config/config.go b/pkg/config/config.go index 6e4bba5..795ccd0 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -13,9 +13,9 @@ var validTrainStop = regexp.MustCompile(`^[a-zA-Z0-9:_]+$`) type Config struct { // Address is the hostname or ip the web server will listen to - Address string `yaml:"address",default:"127.0.0.1"` + Address string `yaml:"address"` // Port is the tcp port number or service name the web server will listen to - Port string `yaml:"port",default:"8080"` + Port string `yaml:"port"` // Token is the sncf api token Token string `yaml:"token"` // TrainStop is the navitia code of the train stop the webapp will monitor @@ -24,12 +24,18 @@ type Config struct { func (c *Config) validate() error { // address + if c.Address == "" { + c.Address = "127.0.0.1" + } if ip := net.ParseIP(c.Address); ip == nil { if _, err := net.LookupIP(c.Address); err != nil { return newInvalidAddressError(c.Address, err) } } // port + if c.Port == "" { + c.Port = "8080" + } if _, err := net.LookupPort("tcp", c.Port); err != nil { return newInvalidPortError(c.Port, err) } -- cgit v1.2.3