aboutsummaryrefslogtreecommitdiff
path: root/pkg/config/config.go
diff options
context:
space:
mode:
authorJulien Dessaux2021-04-08 17:57:55 +0200
committerJulien Dessaux2021-04-08 17:57:55 +0200
commit13195d209c523d3d45f3456086bce61223950dab (patch)
tree45842afa75b8a91e73ce6c5800fc2086c6ebc1ee /pkg/config/config.go
parentRemoved documentation of a feature that is not yet implemented (diff)
downloadtrains-13195d209c523d3d45f3456086bce61223950dab.tar.gz
trains-13195d209c523d3d45f3456086bce61223950dab.tar.bz2
trains-13195d209c523d3d45f3456086bce61223950dab.zip
Fixed wrong implementation of yaml default values and of the corresponding tests
Diffstat (limited to '')
-rw-r--r--pkg/config/config.go10
1 files changed, 8 insertions, 2 deletions
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)
}