-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconfig.go
43 lines (38 loc) · 883 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
42
43
package main
import (
"fmt"
"github.com/BurntSushi/toml"
"os"
)
// Config of the app
type Config struct {
DiscordSecret string `toml:"discord_secret"`
DiscordStatsSecret string `toml:"discord_stats_secret"`
DiscordAppID string `toml:"discord_app_id"`
DisableStatus bool `toml:"disable_status"`
}
func loadConfig() Config {
config := Config{}
_, err := toml.DecodeFile("config.toml", &config)
if err != nil {
createConfig()
fmt.Println("Created new config file - please fill in discord token")
os.Exit(1)
}
return config
}
func createConfig() {
fillInCfg := Config{
DiscordSecret: "YOUR_DISCORD_BOT_TOKEN",
}
cfgFile, err := os.Create("config.toml")
if err != nil {
panic("Failed to create config.toml")
}
defer cfgFile.Close()
encoder := toml.NewEncoder(cfgFile)
err = encoder.Encode(fillInCfg)
if err != nil {
panic(err)
}
}