Change duration config types

This commit is contained in:
Deluan 2020-07-02 16:41:54 -04:00
parent 5021c0fd0c
commit d2e4cade62
3 changed files with 7 additions and 14 deletions

View file

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"time"
"github.com/deluan/navidrome/consts" "github.com/deluan/navidrome/consts"
"github.com/deluan/navidrome/log" "github.com/deluan/navidrome/log"
@ -15,10 +16,10 @@ type nd struct {
Port int Port int
MusicFolder string MusicFolder string
DataFolder string DataFolder string
ScanInterval string
DbPath string DbPath string
LogLevel string LogLevel string
SessionTimeout string ScanInterval time.Duration
SessionTimeout time.Duration
BaseURL string BaseURL string
UILoginBackgroundURL string UILoginBackgroundURL string
IgnoredArticles string IgnoredArticles string
@ -65,8 +66,8 @@ func SetDefaults() {
viper.SetDefault("datafolder", "./") viper.SetDefault("datafolder", "./")
viper.SetDefault("loglevel", "info") viper.SetDefault("loglevel", "info")
viper.SetDefault("port", 4533) viper.SetDefault("port", 4533)
viper.SetDefault("sessiontimeout", "1h") viper.SetDefault("sessiontimeout", consts.DefaultSessionTimeout)
viper.SetDefault("scaninterval", "1m") viper.SetDefault("scaninterval", time.Minute)
viper.SetDefault("baseurl", "") viper.SetDefault("baseurl", "")
viper.SetDefault("uiloginbackgroundurl", "") viper.SetDefault("uiloginbackgroundurl", "")
viper.SetDefault("enabletranscodingconfig", false) viper.SetDefault("enabletranscodingconfig", false)

View file

@ -44,11 +44,7 @@ func CreateToken(u *model.User) (string, error) {
func getSessionTimeOut() time.Duration { func getSessionTimeOut() time.Duration {
if sessionTimeOut == 0 { if sessionTimeOut == 0 {
if to, err := time.ParseDuration(conf.Server.SessionTimeout); err != nil { sessionTimeOut = conf.Server.SessionTimeout
sessionTimeOut = consts.DefaultSessionTimeout
} else {
sessionTimeOut = to
}
log.Info("Setting Session Timeout", "value", sessionTimeOut) log.Info("Setting Session Timeout", "value", sessionTimeOut)
} }
return sessionTimeOut return sessionTimeOut

View file

@ -75,11 +75,7 @@ func (a *Server) initRoutes() {
} }
func (a *Server) initScanner() { func (a *Server) initScanner() {
interval, err := time.ParseDuration(conf.Server.ScanInterval) interval := conf.Server.ScanInterval
if err != nil {
log.Error("Invalid interval specification. Using default of 5m", "interval", conf.Server.ScanInterval, err)
interval = 5 * time.Minute
}
if interval == 0 { if interval == 0 {
log.Warn("Scanner is disabled", "interval", conf.Server.ScanInterval) log.Warn("Scanner is disabled", "interval", conf.Server.ScanInterval)
return return