-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenv.go
84 lines (69 loc) · 1.31 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
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"log"
"os"
"strconv"
"strings"
)
func GetAPIKey() string {
value, isSet := os.LookupEnv("API_KEY")
if !isSet {
log.Panic("Missing environment variable 'API_KEY'")
}
return value
}
func GetZoneID() string {
value, isSet := os.LookupEnv("ZONE_ID")
if !isSet {
log.Panic("Missing environment variable 'ZONE_ID'")
}
return value
}
func GetDomainNames() []string {
value, isSet := os.LookupEnv("DOMAIN_NAMES")
if !isSet {
log.Panic("Missing environment variable 'DOMAIN_NAMES'")
}
return strings.Split(value, ",")
}
func UseIPv4() bool {
value, isSet := os.LookupEnv("RECORD_TYPES")
if !isSet {
return true
}
switch value {
case "A", "*":
return true
case "AAAA":
return false
default:
log.Panicf("Unrecognized value '%v' for 'RECORD_TYPES'", value)
return false
}
}
func UseIPv6() bool {
value, isSet := os.LookupEnv("RECORD_TYPES")
if !isSet {
return false
}
switch value {
case "AAAA", "*":
return true
case "A":
return false
default:
log.Panicf("Unrecognized value '%v' for 'RECORD_TYPES'", value)
return false
}
}
func GetInterval() int {
value, isSet := os.LookupEnv("INTERVAL")
if !isSet {
return 5
}
interval, err := strconv.Atoi(value)
if err != nil {
log.Panic("Error converting 'INTERVAL' to integer: ", err)
}
return interval
}