forked from magoo/AuthTables
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfiguration.go
64 lines (55 loc) · 1.47 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
58
59
60
61
62
63
64
package main
import (
"os"
"strconv"
)
const (
defaultHost = "redis"
defaultPort = "6379"
defaultPassword = ""
defaultLogLevel = "debug"
defaultBloomSize = 1000000
defaultShard = ""
)
//Configuration holds data from ENV variables, or defaults
type Configuration struct {
Host string
Port string
Password string
LogLevel string
BloomSize uint
Shard string
}
//Global access to configuration variables
var c = getConfig()
func getConfig() (c Configuration) {
configuration := Configuration{}
// set to defaults
configuration.Host = defaultHost
configuration.Port = defaultPort
configuration.Password = defaultPassword
configuration.LogLevel = defaultLogLevel
configuration.BloomSize = defaultBloomSize
configuration.Shard = defaultShard
// override with ENV values, if set
if envVal, envSet := os.LookupEnv("AUTHTABLES_HOST"); envSet {
configuration.Host = envVal
}
if envVal, envSet := os.LookupEnv("AUTHTABLES_PORT"); envSet {
configuration.Port = envVal
}
if envVal, envSet := os.LookupEnv("AUTHTABLES_PW"); envSet {
configuration.Password = envVal
}
if envVal, envSet := os.LookupEnv("AUTHTABLES_LOGLEVEL"); envSet {
configuration.LogLevel = envVal
}
if envVal, envSet := os.LookupEnv("AUTHTABLES_BLOOMSIZE"); envSet {
bs, _ := strconv.ParseUint(envVal, 0, 32)
configuration.BloomSize = uint(bs)
}
if envVal, envSet := os.LookupEnv("AUTHTABLES_SHARD"); envSet {
configuration.Shard = envVal
}
return configuration
}