/
global.go
68 lines (54 loc) · 1.41 KB
/
global.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
59
60
61
62
63
64
65
66
67
68
package global
import (
"flag"
"os"
"github.com/inconshreveable/log15"
"github.com/joho/godotenv"
)
var (
log log15.Logger
local bool
webtest bool
infura string
discord string
discordChannelID string
)
// IsLocal returns wether we are running in local mode or live
func IsLocal() bool {
return local
}
// IsWebtest returns wether we are running in webtest mode
func IsWebtest() bool {
return webtest
}
// GetInfuraKey returns the infura key
func GetInfuraKey() string {
return infura
}
// GetDiscordKey returns the discord key
func GetDiscordKey() string {
return discord
}
// GetDiscordChannelID returns the discord channelId
func GetDiscordChannelID() string {
return discordChannelID
}
// Init loads environment files and reads cmd args
func Init() {
log = log15.New("module", "global")
flag.BoolVar(&local, "local", false, "local mode")
flag.BoolVar(&webtest, "webtest", false, "webtest mode")
flag.Parse()
log.Info("loaded command-line arguments", "local", local, "webtest", webtest)
err := godotenv.Load(".env")
if err != nil {
log.Crit("failed to load .env", "err", err.Error())
panic("")
}
infura = os.Getenv("INFURA_KEY")
log.Info("loaded infura key", "token", infura)
discord = os.Getenv("DISCORD_TOKEN")
log.Info("loaded discord token", "token", discord)
discordChannelID = os.Getenv("DISCORD_CHANNEL_ID")
log.Info("loaded discord channel id", "id", discordChannelID)
}