-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
53 lines (45 loc) · 847 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
48
49
50
51
52
53
package jsonport
import (
"strconv"
)
type Type int
const (
INVALID Type = iota
OBJECT
ARRAY
STRING
NUMBER
BOOL
NULL
)
func (t Type) String() string {
switch t {
case INVALID:
return "INVALID"
case OBJECT:
return "OBJECT"
case ARRAY:
return "ARRAY"
case STRING:
return "STRING"
case NUMBER:
return "NUMBER"
case BOOL:
return "BOOL"
case NULL:
return "NULL"
}
return "UNKNOWN"
}
// A Number represents a JSON number literal.
type Number string
// String returns the literal text of the number.
func (n Number) String() string { return string(n) }
// Float64 returns the number as a float64.
func (n Number) Float64() (float64, error) {
return strconv.ParseFloat(string(n), 64)
}
// Int64 returns the number as an int64.
func (n Number) Int64() (int64, error) {
return strconv.ParseInt(string(n), 10, 64)
}