-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
52 lines (46 loc) · 1.01 KB
/
setup.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
package main
import (
"log"
"strings"
)
var required = []string{"ACCESS_TOKEN", "LANGUAGES"}
var optionalAws = []string{
"AWS_KEY", "AWS_KEY_SECRET", "AWS_API_ID", "AWS_API_STAGE",
}
type awsConfig struct {
key string
secret string
api string
stage string
}
type config struct {
ghToken string
languages []string
aws awsConfig
}
func getConfig() *config {
// check required envs
if !all(required, isSet) {
missing := filter(required, notSet)
log.Fatalf("Missing required variables: %v", missing)
}
config := &config{
ghToken: getEnv(required[0]),
languages: strings.Split(getEnv(required[1]), ","),
}
// all or none of aws envs
if !all(optionalAws, isSet) {
if any(optionalAws, isSet) {
missing := filter(optionalAws, notSet)
log.Fatalf("Missing AWS variables: %v", missing)
}
} else {
config.aws = awsConfig{
key: getEnv(optionalAws[0]),
secret: getEnv(optionalAws[1]),
api: getEnv(optionalAws[2]),
stage: getEnv(optionalAws[3]),
}
}
return config
}