-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathconfiguration.go
57 lines (47 loc) · 1.83 KB
/
configuration.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
package main
import (
"flag"
"os"
"strconv"
log "github.com/Sirupsen/logrus"
)
//Configuration holds data cleaned from our ENV variables or passed through cmd line
type Configuration struct {
Host string
Port string
Password string
Loglevel string
BloomSize uint
Shard string
}
//Global access to configuration variables
var c = readConfig()
func readConfig() (c Configuration) {
//Command Line Flags. If command line flag is blank, use ENV instead
var flagHost string
flag.StringVar(&flagHost, "host", os.Getenv("AUTHTABLES_HOST"), "hostname for redis")
var flagPort string
flag.StringVar(&flagPort, "port", os.Getenv("AUTHTABLES_PORT"), "port for redis")
var flagPW string
flag.StringVar(&flagPW, "password", os.Getenv("AUTHTABLES_PW"), "password for redis")
var flagLoglevel string
flag.StringVar(&flagLoglevel, "loglevel", os.Getenv("AUTHTABLES_LOGLEVEL"), "level of logging (debug, info, warn, error)")
var flagBloomSize uint
d, _ := strconv.ParseUint(os.Getenv("AUTHTABLES_BLOOMSIZE"), 0, 32)
flag.UintVar(&flagBloomSize, "bloomsize", uint(d), "size of bloom filter (default 1e9)")
var flagShard string
flag.StringVar(&flagShard, "shard", os.Getenv("AUTHTABLES_SHARD"), "name of this shard (prefix's keys within redis)")
flag.Parse()
if (flagHost == "" || flagPort == "" || flagLoglevel == "" || flagBloomSize == 0) {
log.Error("Important things are not configured. You need to have your environment variables set, a .env file (docker), or pass valid data in command line arguments.")
}
//We're going to load this with config data. See struct!
configuration := Configuration{}
configuration.Host = flagHost
configuration.Port = flagPort
configuration.Password = flagPW
configuration.Loglevel = flagLoglevel
configuration.BloomSize = flagBloomSize
configuration.Shard = flagShard
return configuration
}