forked from PoC-Consortium/aggregator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
47 lines (41 loc) · 881 Bytes
/
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
package main
import (
"strconv"
"sync/atomic"
)
// atomic boolean
type atomicBool struct {
flag int32
}
func (b *atomicBool) Set(value bool) {
var i int32
if value {
i = 1
}
atomic.StoreInt32(&(b.flag), i)
}
func (b *atomicBool) Get() bool {
if atomic.LoadInt32(&(b.flag)) != 0 {
return true
}
return false
}
// FlexUInt64 handling json type inconsistencies of pools and wallets. integers are sometimes sent as string
// https://engineering.bitnami.com/articles/dealing-with-json-with-non-homogeneous-types-in-go.html
type FlexUInt64 int
// UnmarshalJSON JSON unmarshaller
func (fi *FlexUInt64) UnmarshalJSON(b []byte) error {
if b[0] != '"' {
return jsonx.Unmarshal(b, (*int)(fi))
}
var s string
if err := jsonx.Unmarshal(b, &s); err != nil {
return err
}
i, err := strconv.Atoi(s)
if err != nil {
return err
}
*fi = FlexUInt64(i)
return nil
}