forked from goraz/onion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
102 lines (78 loc) · 1.61 KB
/
types.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package onion
import (
"sync"
"time"
)
var (
globalLock = &sync.RWMutex{}
)
// String is the string value holder, with safe lock for concurrent reload
type String interface {
String() string
}
// Int is the int value holder, with safe lock for concurrent reload
type Int interface {
// Return the int value
Int() int
// Return int64 value
Int64() int64
// Return duration value
Duration() time.Duration
}
// Bool is the bool value holder, with safe lock for concurrent reload
type Bool interface {
// The bool value
Bool() bool
}
// Float is the float value holder, with safe lock for concurrent reload
type Float interface {
Float32() float32
Float64() float64
}
type stringHolder struct {
value *string
}
func (sh stringHolder) String() string {
globalLock.RLock()
defer globalLock.RUnlock()
return *sh.value
}
type intHolder struct {
value *int64
}
func (ih intHolder) Int() int {
globalLock.RLock()
defer globalLock.RUnlock()
return int(*ih.value)
}
func (ih intHolder) Int64() int64 {
globalLock.RLock()
defer globalLock.RUnlock()
return *ih.value
}
func (ih intHolder) Duration() time.Duration {
globalLock.RLock()
defer globalLock.RUnlock()
return time.Duration(*ih.value)
}
type boolHolder struct {
value *bool
}
func (bh boolHolder) Bool() bool {
globalLock.RLock()
defer globalLock.RUnlock()
return *bh.value
}
type floatHolder struct {
value *float64
}
func (fh floatHolder) Float32() float32 {
globalLock.RLock()
defer globalLock.RUnlock()
return float32(*fh.value)
}
func (fh floatHolder) Float64() float64 {
globalLock.RLock()
defer globalLock.RUnlock()
return *fh.value
}