forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnull_uint64.go
45 lines (36 loc) · 824 Bytes
/
null_uint64.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
package types
import (
"strconv"
)
// NullUint64 is a wrapper around uint64 values that can be null or an unint64.
// Use IsSet to check if the value is provided, instead of checking against 0.
type NullUint64 struct {
IsSet bool
Value uint64
}
// ParseStringValue is used to parse a user provided flag argument.
func (n *NullUint64) ParseStringValue(val string) error {
if val == "" {
n.Value = 0
n.IsSet = false
return nil
}
uint64Val, err := strconv.ParseUint(val, 10, 64)
if err != nil {
n.Value = 0
n.IsSet = false
return err
}
n.Value = uint64Val
n.IsSet = true
return nil
}
func (n *NullUint64) UnmarshalJSON(rawJSON []byte) error {
stringValue := string(rawJSON)
if stringValue == JsonNull {
n.Value = 0
n.IsSet = false
return nil
}
return n.ParseStringValue(stringValue)
}