~vladh/radio-api

d1b630813b94022796e6caae67fffcbae9c5aaad — Vlad-Stefan Harbuz 1 year, 3 months ago 18eda25
improve config code
1 files changed, 10 insertions(+), 1 deletions(-)

M main.go
M main.go => main.go +10 -1
@@ 61,7 61,16 @@ func isSong(path string) bool {

func getConfig() Config {
	var config Config
	_, err := toml.DecodeFile("config.toml", &config)

	configDir := os.Getenv("XDG_CONFIG_HOME")
	if len(configDir) == 0 {
		homedir, err := os.UserHomeDir()
		if err != nil { panic(err) }
		configDir = homedir + "/.config/"
	}
	configPath := configDir + "/radio-api/config.toml"

	_, err := toml.DecodeFile(configPath, &config)
	if err != nil { log.Fatal(err) }
	return config
}