update sanity check when parsing config
This commit is contained in:
15
config.go
15
config.go
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"regexp"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -132,6 +133,20 @@ func (c *Config) LoadFile(path string) error {
|
||||
return err
|
||||
}
|
||||
c.apps[v.Name] = a
|
||||
for k, _ := range a.schedule {
|
||||
if dur, ok := c.ScheduleDuration[k]; ok {
|
||||
re := regexp.MustCompile(`^forever|([0-9]+(h|d|m|y))+$`)
|
||||
if !re.MatchString(dur) {
|
||||
err := errors.New("incorrect schedule duration")
|
||||
log.WithFields(log.Fields{"path": path, "app": v.Name, "schedule": k, "error": err}).Errorf("")
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
err := errors.New("undefined schedule duration")
|
||||
log.WithFields(log.Fields{"path": path, "app": v.Name, "schedule": k, "error": err}).Errorf("")
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user