-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfg.go
96 lines (73 loc) · 1.9 KB
/
cfg.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"fmt"
"log"
"os"
"strconv"
"github.com/joho/godotenv"
)
// loadDotEnv loads your config from the .env file
func loadDotEnv() {
if _, err := os.Stat(".env"); err != nil {
return
}
if err := godotenv.Load(); err != nil {
log.Fatal("Error loading .env file")
}
}
// getSlackToken fetches the token used to authenticate to slack
func getSlackToken() (string, error) {
value := os.Getenv("SLACK_TOKEN")
if len(value) == 0 {
return "", fmt.Errorf("Missing SLACK_TOKEN ENV variable. Check --help for options")
}
return value, nil
}
// getSlackSigningSecret fetches the token used to validate messages from slack
func getSlackSigningSecret() (string, error) {
value := os.Getenv("SLACK_SIGNING_SECRET")
if len(value) == 0 {
return "", fmt.Errorf("Missing SLACK_SIGNING_SECRET ENV variable. Check --help for options")
}
return value, nil
}
// getRedisAddr fetches the address (host:port) to connect to redis
func getRedisAddr() (string, error) {
value := os.Getenv("REDIS_ADDR")
if len(value) == 0 {
return "", fmt.Errorf("Missing REDIS_ADDR ENV variable. Check --help for options")
}
return value, nil
}
// getRedisPwd fetches the password used to connect to redis (defaults to "")
func getRedisPwd() string {
return os.Getenv("REDIS_PWD")
}
// getRedisDB fetches the redis DB instance to connect to (defaults to 0)
func getRedisDB() int {
value := os.Getenv("REDIS_DB")
if len(value) == 0 {
return 0
}
i, err := strconv.Atoi(value)
if err != nil {
return 0
}
return i
}
// getRulesFileLocation fetches the address of the rules.json to load
func getRulesFileLocation() string {
value := os.Getenv("JSON_RULES")
if len(value) == 0 {
return "rules.json"
}
return value
}
// getWebListen fetches the listening server address for the web server
func getWebListen() string {
value := os.Getenv("WEB_ADDR")
if len(value) == 0 {
return ":8000"
}
return value
}