-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathenv.go
37 lines (33 loc) · 784 Bytes
/
env.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
package fingerproxy
import (
"log"
"os"
"strconv"
"strings"
)
func envWithDefault(key string, defaultVal string) string {
if envVal, ok := os.LookupEnv(key); ok {
return envVal
}
return defaultVal
}
func envWithDefaultUint(key string, defaultVal uint) uint {
if envVal, ok := os.LookupEnv(key); ok {
if ret, err := strconv.ParseUint(envVal, 10, 0); err == nil {
return uint(ret)
} else {
log.Fatalf("invalid environment variable $%s, expect uint, actual %s: %s", key, envVal, err)
}
}
return defaultVal
}
func envWithDefaultBool(key string, defaultVal bool) bool {
if envVal, ok := os.LookupEnv(key); ok {
if strings.ToLower(envVal) == "true" {
return true
} else if strings.ToLower(envVal) == "false" {
return false
}
}
return defaultVal
}