-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv.go
49 lines (42 loc) · 1.03 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
package sca_base_module_config
import (
"github.com/golang-infrastructure/go-pointer"
"os"
"strconv"
"strings"
)
const ScaAutoInitConfigEnvName = "SCA_AUTO_INIT_CONFIG"
func GetEnvString(name string) *string {
env, b := os.LookupEnv(name)
if !b {
return nil
}
return pointer.ToPointer(env)
}
func GetEnvStringOrDefault(name, defaultValue string) string {
return pointer.FromPointerOrDefault(GetEnvString(name), defaultValue)
}
func GetEnvBool(name string) *bool {
env, b := os.LookupEnv(name)
if !b {
return nil
}
return pointer.ToPointer(strings.ToLower(env) == "true")
}
func GetEnvBoolOrDefault(name string, defaultValue bool) bool {
return pointer.FromPointerOrDefault(GetEnvBool(name), defaultValue)
}
func GetEnvInt(name string) *int {
env, b := os.LookupEnv(name)
if !b {
return nil
}
atoi, err := strconv.Atoi(env)
if err != nil {
return nil
}
return pointer.ToPointer(atoi)
}
func GetEnvIntOrDefault(name string, defaultValue int) int {
return pointer.FromPointerOrDefault(GetEnvInt(name), defaultValue)
}