-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvironment.go
63 lines (51 loc) · 1.03 KB
/
environment.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
package main
import (
"os"
"sigs.k8s.io/yaml"
"strconv"
)
func PopulateBooleanFromEnvironment(name string, variable *bool) bool {
value, present := os.LookupEnv(name)
if !present {
return false
}
v, err := strconv.ParseBool(value)
if err != nil {
return false
}
*variable = v
return true
}
func PopulateStringFromEnvironment(name string, variable *string) bool {
value, present := os.LookupEnv(name)
if !present {
return false
}
*variable = value
return true
}
func PopulateRepositoriesFromEnvironment(name string, variable *[]Repository) bool {
value, present := os.LookupEnv(name)
if !present {
return false
}
repos := make([]Repository, 0)
err := yaml.Unmarshal([]byte(value), &repos)
if err != nil {
return false
}
*variable = repos
return true
}
func PopulateDurationFromEnvironment(name string, variable *Duration) bool {
value, present := os.LookupEnv(name)
if !present {
return false
}
duration, err := ParseDuration(value)
if err != nil {
return false
}
*variable = duration
return true
}