forked from dinofizz/diskplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
33 lines (29 loc) · 942 Bytes
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package diskplayer
import (
"fmt"
"github.com/spf13/viper"
"log"
)
// ReadConfig reads in the configuration values from the diskplayer.yaml configuration file.
func ReadConfig(n string) {
viper.SetConfigName(n)
viper.AddConfigPath("/etc/diskplayer/")
viper.AddConfigPath("$HOME/.config/diskplayer/")
viper.AddConfigPath(".")
viper.SetDefault("token.path", "token.json")
viper.SetDefault("spotify.callback_url", "http://localhost:8080/callback")
viper.SetDefault("recorder.server_port", "3000")
err := viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
}
// ConfigValue returns the configuration value identified by the provided key.
// If none is found the application quits with an error message and exit code 1.
func ConfigValue(key string) string {
value := viper.GetString(key)
if value == "" {
log.Fatalf("Configuration value \"%s\" is empty.", key)
}
return value
}