-
Notifications
You must be signed in to change notification settings - Fork 0
/
nullPath.go
53 lines (42 loc) · 963 Bytes
/
nullPath.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 pgeo
import (
"database/sql/driver"
"encoding/json"
"github.com/volatiletech/sqlboiler/randomize"
)
type NullPath struct {
Path
Valid bool
}
func (p NullPath) Value() (driver.Value, error) {
if !p.Valid {
return nil, nil
}
return valuePath(p.Path)
}
func (p *NullPath) Scan(src interface{}) error {
if src == nil {
p.Path, p.Valid = NewPath([]Point{Point{}, Point{}}, false), false
return nil
}
p.Valid = true
return scanPath(&p.Path, src)
}
func (p *NullPath) MarshalJSON() ([]byte, error) {
if !p.Valid {
return []byte("null"), nil
}
return json.Marshal(p.Path)
}
func (p *NullPath) UnmarshalJSON(data []byte) error {
if string(data) == "" || string(data) == "null" {
p.Valid = false
return nil
}
var err = json.Unmarshal(data, p.Path)
p.Valid = err == nil
return err
}
func (o *NullPath) Randomize(seed *randomize.Seed, fieldType string, shouldBeNull bool) {
*o = NewNullPath(NewRandPath(), !shouldBeNull)
}