mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-02 08:31:27 +03:00
Add option to specify ConfigFile path
This commit is contained in:
parent
17e51756ef
commit
cccd0235cf
@ -13,6 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type nd struct {
|
type nd struct {
|
||||||
|
ConfigFile string `default:"./navidrome.toml"`
|
||||||
Port string `default:"4533"`
|
Port string `default:"4533"`
|
||||||
MusicFolder string `default:"./music"`
|
MusicFolder string `default:"./music"`
|
||||||
DataFolder string `default:"./"`
|
DataFolder string `default:"./"`
|
||||||
@ -39,6 +40,28 @@ type nd struct {
|
|||||||
|
|
||||||
var Server = &nd{}
|
var Server = &nd{}
|
||||||
|
|
||||||
|
// TODO refactor configuration and use something different. Maybe https://github.com/spf13/cobra
|
||||||
|
// This function loads the config just load the ConfigFile. This is very cumbersome, but doesn't
|
||||||
|
// seem there's a simpler way to do thiswith multiconfig. Time to replace this library?
|
||||||
|
func configFile() string {
|
||||||
|
conf := &nd{}
|
||||||
|
loader := multiconfig.MultiLoader(
|
||||||
|
&multiconfig.TagLoader{},
|
||||||
|
&multiconfig.EnvironmentLoader{},
|
||||||
|
&multiconfig.FlagLoader{},
|
||||||
|
)
|
||||||
|
d := &multiconfig.DefaultLoader{}
|
||||||
|
d.Loader = loader
|
||||||
|
d.Validator = multiconfig.MultiValidator(&multiconfig.RequiredValidator{})
|
||||||
|
if err := d.Load(conf); err != nil {
|
||||||
|
return consts.LocalConfigFile
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(conf.ConfigFile); err == nil {
|
||||||
|
return conf.ConfigFile
|
||||||
|
}
|
||||||
|
return consts.LocalConfigFile
|
||||||
|
}
|
||||||
|
|
||||||
func newWithPath(path string, skipFlags ...bool) *multiconfig.DefaultLoader {
|
func newWithPath(path string, skipFlags ...bool) *multiconfig.DefaultLoader {
|
||||||
var loaders []multiconfig.Loader
|
var loaders []multiconfig.Loader
|
||||||
|
|
||||||
@ -96,5 +119,5 @@ func LoadFromFile(confFile string, skipFlags ...bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Load() {
|
func Load() {
|
||||||
LoadFromFile(consts.LocalConfigFile)
|
LoadFromFile(configFile())
|
||||||
}
|
}
|
||||||
|
@ -2,5 +2,6 @@ DevDisableAuthentication = false
|
|||||||
User = "deluan"
|
User = "deluan"
|
||||||
Password = "wordpass"
|
Password = "wordpass"
|
||||||
DbPath = "file::memory:?cache=shared"
|
DbPath = "file::memory:?cache=shared"
|
||||||
MusicFolder = "./tests/itunes-library.xml"
|
MusicFolder = "./tests/fixtures"
|
||||||
|
DataFolder = "data/tests"
|
||||||
DownsampleCommand = "ffmpeg -i %s -b:a %bk mp3 -"
|
DownsampleCommand = "ffmpeg -i %s -b:a %bk mp3 -"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user