-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
60 lines (53 loc) · 888 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
54
55
56
57
58
59
60
package util
import (
"encoding/json"
"fmt"
"strconv"
)
type Obj map[string]any
type Objs []Obj
type NullFloat64 struct {
Null bool
V float64
}
func (o *NullFloat64) Scan(v any) error {
*o = NullFloat64{}
if v == nil {
o.Null = true
return nil
}
f, err := strconv.ParseFloat(fmt.Sprint(v), 64)
if err != nil {
return err
}
(*o).V = f
return nil
}
func (o NullFloat64) MarshalJSON() ([]byte, error) {
if o.Null {
return []byte("null"), nil
}
return json.Marshal(o.V)
}
func (o *Objs) Scan(value interface{}) error {
if value == nil {
*o = Objs{}
return nil
}
bytes, ok := value.([]byte)
if !ok {
return ErrNotBytes
}
return json.Unmarshal(bytes, o)
}
func (o *Obj) Scan(value interface{}) error {
if value == nil {
*o = Obj{}
return nil
}
bytes, ok := value.([]byte)
if !ok {
return ErrNotBytes
}
return json.Unmarshal(bytes, o)
}