-
Notifications
You must be signed in to change notification settings - Fork 921
/
config.go
58 lines (45 loc) · 2.16 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 common
import (
"github.com/jonas747/yagpdb/common/config"
"github.com/pkg/errors"
"strings"
)
var (
ConfOwner = config.RegisterOption("yagpdb.owner", "ID of the owner of the bot", nil)
ConfClientID = config.RegisterOption("yagpdb.clientid", "Client ID of the discord application", nil)
ConfClientSecret = config.RegisterOption("yagpdb.clientsecret", "Client Secret of the discord application", nil)
ConfBotToken = config.RegisterOption("yagpdb.bottoken", "Token of the bot user", nil)
ConfHost = config.RegisterOption("yagpdb.host", "Host without the protocol, example: example.com, used by the webserver", nil)
ConfEmail = config.RegisterOption("yagpdb.email", "Email used when fetching lets encrypt certificate", "")
ConfPQHost = config.RegisterOption("yagpdb.pqhost", "Postgres host", "localhost")
ConfPQUsername = config.RegisterOption("yagpdb.pqusername", "Postgres user", "postgres")
ConfPQPassword = config.RegisterOption("yagpdb.pqpassword", "Postgres passoword", "")
ConfPQDB = config.RegisterOption("yagpdb.pqdb", "Postgres database", "yagpdb")
ConfRedis = config.RegisterOption("yagpdb.redis", "Redis address", "localhost:6379")
ConfMaxCCR = config.RegisterOption("yagpdb.max_ccr", "Maximum number of concurrent outgoing requests to discord", 25)
ConfDisableKeepalives = config.RegisterOption("yagpdb.disable_keepalives", "Disables keepalive connections for outgoing requests to discord, this shouldn't be needed but i had networking issues once so i had to", false)
ConfDogStatsdAddress = config.RegisterOption("yagpdb.dogstatsdaddress", "dogstatsd address", "")
)
var configLoaded = false
func LoadConfig() (err error) {
if configLoaded {
return nil
}
configLoaded = true
config.AddSource(&config.EnvSource{})
config.Load()
requiredConf := []*config.ConfigOption{
ConfOwner,
ConfClientID,
ConfClientSecret,
ConfBotToken,
ConfHost,
}
for _, v := range requiredConf {
if v.LoadedValue == nil {
envFormat := strings.ToUpper(strings.Replace(v.Name, ".", "_", -1))
return errors.Errorf("Did not set required config option: %q (%s as env var)", v.Name, envFormat)
}
}
return nil
}