-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
50 lines (40 loc) · 1.01 KB
/
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
42
43
44
45
46
47
48
49
50
package main
import (
"log"
"os"
"github.com/spf13/viper"
)
func LoadConfig() Config {
viper.SetConfigName("config")
viper.AddConfigPath(".")
viper.SetConfigType("toml")
err := viper.ReadInConfig()
if err != nil {
log.Println("Error reading config file, generating new one...")
genConfig()
}
var config Config
err = viper.Unmarshal(&config)
if err != nil {
log.Println("Error unmarshalling config file, generating new one...")
genConfig()
}
return config
}
func genConfig() {
viper.SetConfigName("config")
viper.AddConfigPath(".")
viper.SetConfigType("toml")
viper.SetDefault("GroupName", "steamgroupname")
viper.SetDefault("WebhookURL", "https://discord.com/api/webhooks/id")
viper.SetDefault("CheckFreq", 60)
viper.SetDefault("ShowSteamPrefix", true)
err := viper.WriteConfigAs("config.toml")
if err != nil {
log.Println("Error writing config file:", err)
os.Exit(1)
}
log.Println("Config file generated, please fill in the details and re-run the program.")
CreateDatabase()
os.Exit(1)
}