-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
41 lines (33 loc) · 870 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
34
35
36
37
38
39
40
41
package orchestration
import (
"log/slog"
"os"
"github.com/spf13/viper"
"github.com/KarnerTh/qlookout/core/config"
)
func setupConfig(configPath string) config.Config {
homeDir, err := os.UserHomeDir()
if err != nil {
slog.Error("Could not get home dir", slog.Any("error", err))
panic("Could not get home dir")
}
viper.SetConfigType("yaml")
if configPath != "" {
viper.SetConfigFile(configPath)
} else {
viper.AddConfigPath(homeDir)
viper.SetEnvPrefix("QL")
viper.AutomaticEnv()
viper.SetConfigName(".qlookout")
}
if err := viper.ReadInConfig(); err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
// Config file not required
slog.Info("Starting without config file")
} else {
slog.Error("Could not read config", slog.Any("error", err))
panic("Could not read config")
}
}
return config.New(homeDir)
}