navidrome/conf/configuration.go

81 lines
1.8 KiB
Go
Raw Normal View History

2016-03-30 06:05:57 +02:00
package conf
import (
"os"
"github.com/cloudsonic/sonic-server/log"
2016-03-30 06:05:57 +02:00
"github.com/koding/multiconfig"
)
2017-04-01 15:47:14 +02:00
type sonic struct {
Port string `default:"4533"`
MusicFolder string `default:"./music"`
2020-01-15 00:55:12 +01:00
DbPath string `default:"./data/cloudsonic.db"`
2016-03-30 06:05:57 +02:00
IgnoredArticles string `default:"The El La Los Las Le Les Os As O A"`
IndexGroups string `default:"A B C D E F G H I J K L M N O P Q R S T U V W X-Z(XYZ) [Unknown]([)"`
DisableDownsampling bool `default:"false"`
DownsampleCommand string `default:"ffmpeg -i %s -map 0:0 -b:a %bk -v 0 -f mp3 -"`
ProbeCommand string `default:"ffmpeg %s -f ffmetadata"`
PlsIgnoreFolders bool `default:"true"`
PlsIgnoredPatterns string `default:"^iCloud;\\~"`
// DevFlags
LogLevel string `default:"info"`
DevDisableAuthentication bool `default:"false"`
DevDisableFileCheck bool `default:"false"`
2020-01-15 23:48:46 +01:00
DevDisableBanner bool `default:"false"`
DevInitialPassword string `default:""`
2016-03-30 06:05:57 +02:00
}
2017-04-01 15:47:14 +02:00
var Sonic *sonic
2016-03-30 06:05:57 +02:00
func LoadFromFlags() {
l := &multiconfig.FlagLoader{}
2017-04-01 15:47:14 +02:00
l.Load(Sonic)
2016-03-30 06:05:57 +02:00
}
2020-01-08 16:25:23 +01:00
func LoadFromEnv() {
port := os.Getenv("PORT")
if port != "" {
Sonic.Port = port
}
l := &multiconfig.EnvironmentLoader{}
2020-01-20 23:35:04 +01:00
err := l.Load(Sonic)
if err != nil {
log.Error("Error parsing configuration from environment")
}
2020-01-08 16:25:23 +01:00
}
func LoadFromTags() {
l := &multiconfig.TagLoader{}
l.Load(Sonic)
}
2016-03-30 06:05:57 +02:00
func LoadFromFile(tomlFile string) {
l := &multiconfig.TOMLLoader{Path: tomlFile}
2017-04-01 15:47:14 +02:00
err := l.Load(Sonic)
2016-03-30 06:05:57 +02:00
if err != nil {
2020-01-15 17:02:27 +01:00
log.Error("Error loading configuration file", "file", tomlFile, err)
2016-03-30 06:05:57 +02:00
}
}
func LoadFromLocalFile() {
2017-04-01 15:47:14 +02:00
if _, err := os.Stat("./sonic.toml"); err == nil {
LoadFromFile("./sonic.toml")
2016-03-30 06:05:57 +02:00
}
}
2020-01-08 16:25:23 +01:00
func Load() {
LoadFromLocalFile()
LoadFromEnv()
LoadFromFlags()
2020-01-20 23:35:04 +01:00
log.SetLogLevelString(Sonic.LogLevel)
2020-01-08 16:25:23 +01:00
}
2016-03-30 06:05:57 +02:00
func init() {
2017-04-01 15:47:14 +02:00
Sonic = new(sonic)
2020-01-08 16:25:23 +01:00
LoadFromTags()
2016-03-30 06:05:57 +02:00
}