-
Notifications
You must be signed in to change notification settings - Fork 1
/
integers.go
74 lines (54 loc) · 1.32 KB
/
integers.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
package typenv
import (
"os"
"strconv"
)
// Int64 returns given registered environment variable and mark as used
func Int64(name string, defaults ...int64) int64 {
val, set := os.LookupEnv(name)
if !set {
if 1 == len(defaults) {
return defaults[0]
}
if global, ok := integers[name]; ok {
return global
}
}
i64, err := strconv.ParseInt(val, 10, 0)
if nil != err {
if 1 == len(defaults) {
return defaults[0]
}
if global, ok := integers[name]; ok {
return global
}
}
return i64
}
// Int32 returns given registered environment variable and mark as used
func Int32(name string, defaults ...int32) int32 {
var subdefaults []int64
if 1 == len(defaults) {
subdefaults = []int64{int64(defaults[0])}
}
i64 := Int64(name, subdefaults...)
return int32(i64)
}
// Int8 returns given registered environment variable and mark as used
func Int8(name string, defaults ...int8) int8 {
var subdefaults []int64
if 1 == len(defaults) {
subdefaults = []int64{int64(defaults[0])}
}
i64 := Int64(name, subdefaults...)
return int8(i64)
}
// Int returns given registered environment variable and mark as used
func Int(name string, defaults ...int) int {
var subdefaults []int64
if 1 == len(defaults) {
subdefaults = []int64{int64(defaults[0])}
}
i64 := Int64(name, subdefaults...)
return int(i64)
}