-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
75 lines (56 loc) · 1.8 KB
/
config.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
package storage
import (
"context"
"log"
"os"
"strconv"
lbcf "github.com/lidstromberg/config"
)
var (
//EnvDebugOn controls verbose logging
EnvDebugOn bool
//EnvClientPool is the size of the client pool
EnvClientPool int
)
//preflight config checks
func preflight(ctx context.Context, bc lbcf.ConfigSetting) {
log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds | log.LUTC)
log.Println("Started Storage preflight..")
//get the session config and apply it to the config
bc.LoadConfigMap(ctx, preflightConfigLoader())
//then check that we have everything we need
if bc.GetConfigValue(ctx, "EnvDebugOn") == "" {
log.Fatal("Could not parse environment variable EnvDebugOn")
}
if bc.GetConfigValue(ctx, "EnvStorClientPool") == "" {
log.Fatal("Could not parse environment variable EnvStorClientPool")
}
//set the debug value
constlog, err := strconv.ParseBool(bc.GetConfigValue(ctx, "EnvDebugOn"))
if err != nil {
log.Fatal("Could not parse environment variable EnvDebugOn")
}
EnvDebugOn = constlog
//set the poolsize
pl, err := strconv.ParseInt(bc.GetConfigValue(ctx, "EnvStorClientPool"), 10, 64)
if err != nil {
log.Fatal("Could not parse environment variable EnvStorClientPool")
}
EnvClientPool = int(pl)
log.Println("..Finished Storage preflight.")
}
//preflightConfigLoader loads the config vars
func preflightConfigLoader() map[string]string {
cfm := make(map[string]string)
//EnvDebugOn controls verbose logging
cfm["EnvDebugOn"] = os.Getenv("STOR_DEBUGON")
//EnvStorClientPool is the client poolsize
cfm["EnvStorClientPool"] = os.Getenv("STOR_CLIPOOL")
if cfm["EnvDebugOn"] == "" {
log.Fatal("Could not parse environment variable EnvDebugOn")
}
if cfm["EnvStorClientPool"] == "" {
log.Fatal("Could not parse environment variable EnvStorClientPool")
}
return cfm
}