Mache Start- und Endzeiten konfigurierbar

This commit is contained in:
Gonne 2022-11-15 11:42:23 +01:00
parent 3db1627680
commit f1dd952344
4 changed files with 63 additions and 14 deletions

View file

@ -23,6 +23,14 @@ type Config struct {
}
Date struct {
MinuteGranularity int // Restricts the minutes on which office hours can start and end to multiples of it.
EarliestStartTime struct {
Hour int
Minute int
}
LatestStartTime struct {
Hour int
Minute int
}
}
Request struct {
SecretLength int // Length of the secret token for requests
@ -86,6 +94,26 @@ func validateConfig(conf *Config) error {
err = fmt.Errorf("Validating config: Minute granularity must be between 1 and 60, but is %d.", conf.Date.MinuteGranularity)
log.Println(err.Error())
}
if !(conf.Date.EarliestStartTime.Hour >= 0 && conf.Date.EarliestStartTime.Hour <= 23) {
err = fmt.Errorf("Validating config: Earliest start time hour must be between 0 and 23, but is %d.", conf.Date.EarliestStartTime.Hour)
log.Println(err.Error())
}
if !(conf.Date.EarliestStartTime.Minute >= 0 && conf.Date.EarliestStartTime.Minute <= 60) {
err = fmt.Errorf("Validating config: Earliest start time minute must be between 0 and 60, but is %d.", conf.Date.EarliestStartTime.Minute)
log.Println(err.Error())
}
if !(conf.Date.LatestStartTime.Hour >= 0 && conf.Date.LatestStartTime.Hour <= 23) {
err = fmt.Errorf("Validating config: Latest start time hour must be between 0 and 23, but is %d.", conf.Date.LatestStartTime.Hour)
log.Println(err.Error())
}
if !(conf.Date.LatestStartTime.Minute >= 0 && conf.Date.LatestStartTime.Minute <= 60) {
err = fmt.Errorf("Validating config: Latest start time minute must be between 0 and 60, but is %d.", conf.Date.LatestStartTime.Minute)
log.Println(err.Error())
}
if !(conf.Date.EarliestStartTime.Hour < conf.Date.LatestStartTime.Hour || (conf.Date.EarliestStartTime.Hour == conf.Date.LatestStartTime.Hour && conf.Date.EarliestStartTime.Minute < conf.Date.LatestStartTime.Minute)) {
err = fmt.Errorf("Validating config: Latest start time minute must be after earliest start time.")
log.Println(err.Error())
}
if !(conf.Request.SecretLength >= 5 && conf.Request.SecretLength <= 50) {
err = fmt.Errorf("Validating config: Requests' secret length must be between 5 and 50, but is %d.", conf.Request.SecretLength)
log.Println(err.Error())