-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.go
69 lines (62 loc) · 1.44 KB
/
helpers.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
package main
import (
"github.com/rs/zerolog/log"
"os"
"strconv"
)
func LookupEnvOrUint(key string, defaultVal uint) uint {
if val, ok := os.LookupEnv(key); ok {
v, err := strconv.ParseUint(val, 10, 32)
if err != nil {
log.Fatal().Msgf("LookupEnvOrUint[%s]: %v", key, err)
}
return uint(v)
}
return defaultVal
}
func LookupEnvOrUint64(key string, defaultVal uint64) uint64 {
if val, ok := os.LookupEnv(key); ok {
v, err := strconv.ParseUint(val, 10, 64)
if err != nil {
log.Fatal().Msgf("LookupEnvOrUint64[%s]: %v", key, err)
}
return v
}
return defaultVal
}
func LookupEnvOrInt(key string, defaultVal int) int {
if val, ok := os.LookupEnv(key); ok {
v, err := strconv.Atoi(val)
if err != nil {
log.Fatal().Msgf("LookupEnvOrInt[%s]: %v", key, err)
}
return v
}
return defaultVal
}
func LookupEnvOrInt64(key string, defaultVal int64) int64 {
if val, ok := os.LookupEnv(key); ok {
v, err := strconv.ParseInt(val, 10, 64)
if err != nil {
log.Fatal().Msgf("LookupEnvOrInt64[%s]: %v", key, err)
}
return v
}
return defaultVal
}
func LookupEnvOrString(key string, defaultVal string) string {
if val, ok := os.LookupEnv(key); ok {
return val
}
return defaultVal
}
func LookupEnvOrBool(key string, defaultVal bool) bool {
if val, ok := os.LookupEnv(key); ok {
v, err := strconv.ParseBool(val)
if err != nil {
log.Fatal().Msgf("LookupEnvOrBool[%s]: %v", key, err)
}
return v
}
return defaultVal
}