-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenv.go
72 lines (55 loc) · 1.42 KB
/
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
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
package service
import (
"os"
"strconv"
"strings"
)
const (
// EnvPort is the primary port to serve everything on.
EnvPort = "PORT"
// EnvGRPCPort serves GRPC on a separate port
EnvGRPCPort = "GRPC_PORT"
// EnvDebug enables debug output
EnvDebug = "SERVICE_DEBUG"
// EnvInsecureVerifySkip disables TLS verification
EnvInsecureVerifySkip = "INSECURE_VERIFY_SKIP"
// EnvTLSDisabled will disable TLS (will only support HTTP/1 requests)
EnvTLSDisabled = "TLS_DISABLED"
// EnvCorsEnable env var (default: false)
EnvCorsEnable = "CORS_ENABLE"
// EnvCorsDebug env var (default: false)
EnvCorsDebug = "CORS_DEBUG"
// EnvCorsAllowedOrigins env var
EnvCorsAllowedOrigins = "CORS_ALLOWED_ORIGINS"
// EnvCorsAllowedMethods env var
EnvCorsAllowedMethods = "CORS_ALLOWED_METHODS"
// EnvCorsAllowedHeaders env var
EnvCorsAllowedHeaders = "CORS_ALLOWED_HEADERS"
)
func envBool(env string) bool {
v := strings.ToLower(strings.TrimSpace(os.Getenv(env)))
switch v {
case "false", "0", "":
return false
}
return true
}
func envInt(env string) int {
val, _ := strconv.Atoi(os.Getenv(env))
return val
}
func envStrings(env string) []string {
var (
v = os.Getenv(env)
result []string
)
switch {
case strings.Contains(env, ","):
result = strings.Split(v, ",")
case strings.Contains(env, "|"):
result = strings.Split(v, "|")
case strings.Contains(env, ":"):
result = strings.Split(v, ":")
}
return result
}