-
Notifications
You must be signed in to change notification settings - Fork 14
/
args.go
42 lines (37 loc) · 884 Bytes
/
args.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
package setup
import (
"os"
"strconv"
)
type args struct {
StatsFrequency int `json:"stats_frequency"`
EventEndpoint string `json:"event_endpoint"`
HealthCheckEndpoint string `json:"healthcheck_endpoint"`
}
func GetArgs() *args {
return &args{
StatsFrequency: getIntValue(30, "STATS_FREQUENCY"),
EventEndpoint: getStringValue("http://app:8080/events", "EVENT_ENDPOINT"),
HealthCheckEndpoint: getStringValue("http://app:8080/version", "HEALTH_CHECK_ENDPOINT"),
}
}
func getStringValue(defValue string, varName string) string {
value := defValue
env := os.Getenv(varName)
if len(env) > 0 {
value = env
}
return value
}
func getIntValue(defValue int, varName string) int {
value := defValue
env := os.Getenv(varName)
if len(env) > 0 {
i, err := strconv.Atoi(env)
if err != nil {
return value
}
value = i
}
return value
}