-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_examples_test.go
More file actions
94 lines (83 loc) · 1.69 KB
/
config_examples_test.go
File metadata and controls
94 lines (83 loc) · 1.69 KB
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
85
86
87
88
89
90
91
92
93
94
package config
import (
"fmt"
"math"
)
func ExampleConfig_GetFloat64Ok() {
c := New()
c.Put("float32", float32(1.5))
c.Put("float64", float64(2.5))
c.Put("int", int(2))
fmt.Println(c.GetFloat64Ok("float32"))
fmt.Println(c.GetFloat64Ok("float64"))
fmt.Println(c.GetFloat64Ok("int"))
fmt.Println(c.GetFloat64Ok("does not exist"))
//Output:
//1.5 true
//2.5 true
//0 false
//0 false
}
func ExampleConfig_GetInt64Ok() {
c := New()
c.Put("byte", byte(1))
c.Put("uint8", uint8(2))
c.Put("int8", int8(3))
c.Put("uint16", uint16(4))
c.Put("int16", int16(5))
c.Put("uint32", uint32(6))
c.Put("int32", int32(7))
c.Put("int", int(8))
c.Put("uint64", uint64(9))
c.Put("int64", int64(10))
c.Put("ooh", uint64(math.MaxUint64))
c.Put("string", "foobar")
fmt.Println(c.GetInt64Ok("byte"))
fmt.Println(c.GetInt64Ok("uint8"))
fmt.Println(c.GetInt64Ok("int8"))
fmt.Println(c.GetInt64Ok("uint16"))
fmt.Println(c.GetInt64Ok("int16"))
fmt.Println(c.GetInt64Ok("uint32"))
fmt.Println(c.GetInt64Ok("int32"))
fmt.Println(c.GetInt64Ok("int"))
fmt.Println(c.GetInt64Ok("uint64"))
fmt.Println(c.GetInt64Ok("int64"))
fmt.Println(c.GetInt64Ok("ooh"))
fmt.Println(c.GetInt64Ok("string"))
fmt.Println(c.GetInt64Ok("does not exist"))
//Output:
//1 true
//2 true
//3 true
//4 true
//5 true
//6 true
//7 true
//8 true
//9 true
//10 true
//-1 true
//0 false
//0 false
}
func ExampleConfig_GetValuesOk() {
c := New()
c.Put("a.b", 1)
c.Put("a.c", 2)
c.Put("d", 3)
printlnOk := func(key string) {
_, ok := c.GetValuesOk(key)
fmt.Println(ok)
}
printlnOk("a")
printlnOk("a.b")
printlnOk("a.c")
printlnOk("d")
printlnOk("does not exist")
//Output:
//true
//false
//false
//false
//false
}