This repository has been archived by the owner on Dec 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
config.go
58 lines (53 loc) · 1.5 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
51
52
53
54
55
56
57
58
package main
import (
"errors"
"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
"log"
)
var o = &Options{}
// LoadConfig
func LoadConfig(filename string) (err error) {
// Read the config.toml file
viper.SetConfigType("toml")
viper.SetConfigFile(filename)
//viper.AddConfigPath(".")
err = viper.ReadInConfig()
if err != nil {
return err
}
if o.DiscordToken = viper.GetString("discord.token"); o.DiscordToken == "" {
return errors.New("'token' must be present in config file")
}
if o.DiscordStatus = viper.GetString("discord.status"); o.DiscordStatus == "" {
return errors.New("'status' must be present in config file")
}
if o.DiscordPrefix = viper.GetString("discord.prefix"); o.DiscordPrefix == "" {
return errors.New("'prefix' must be present in config file")
}
if o.DiscordPurgeTime = viper.GetInt64("discord.purgetime"); o.DiscordPurgeTime < 0 {
return errors.New("'purgetime' must be major or equal to 0")
}
o.DiscordPlayStatus = viper.GetBool("discord.playstatus")
if o.DiscordPlayStatus == true {
log.Println("INFO: 'playstatus' true")
} else {
log.Println("INFO: 'playstatus' not set or false")
}
if o.YoutubeToken = viper.GetString("youtube.token"); o.YoutubeToken == "" {
return errors.New("'token' must be present in config file")
}
return nil
}
// Watch
func Watch() {
// Hot reload
viper.WatchConfig()
viper.OnConfigChange(Reload)
}
// Reload
func Reload(e fsnotify.Event) {
log.Println("INFO: The config file changed:", e.Name)
LoadConfig(e.Name)
//StopStream()
}