-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.go
75 lines (58 loc) · 1.78 KB
/
event.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package osv_schema
import (
"database/sql"
"database/sql/driver"
"encoding/json"
)
// ------------------------------------------------- --------------------------------------------------------------------
type Events []*Event
// ------------------------------------------------- --------------------------------------------------------------------
// "events": [
// {
// "introduced": "2.3.0"
// },
// {
// "fixed": "2.3.18"
// }
//
// ]
type Event struct {
// 哪个版本引入的
Introduced string `mapstructure:"introduced" json:"introduced" yaml:"introduced" db:"introduced" bson:"introduced" gorm:"column:introduced"`
// 哪个版本修复的
Fixed string `mapstructure:"fixed" json:"fixed" yaml:"fixed" db:"fixed" bson:"fixed" gorm:"column:fixed"`
// 已知的最后影响版本是哪个
LastAffected string `mapstructure:"last_affected" json:"last_affected" yaml:"last_affected" db:"last_affected" bson:"last_affected" gorm:"column:last_affected"`
Limit string `mapstructure:"limit" json:"limit" yaml:"limit" db:"limit" bson:"limit" gorm:"column:limit"`
}
var _ sql.Scanner = &Event{}
var _ driver.Valuer = &Event{}
func (x *Event) IsIntroduced() bool {
return x.Introduced != ""
}
func (x *Event) IsFixed() bool {
return x.Fixed != ""
}
func (x *Event) IsLastAffected() bool {
return x.LastAffected != ""
}
func (x *Event) IsLimit() bool {
return x.Limit != ""
}
func (x *Event) Value() (driver.Value, error) {
if x == nil {
return nil, nil
}
return json.Marshal(x)
}
func (x *Event) Scan(src any) error {
if src == nil {
return nil
}
bytes, ok := src.([]byte)
if !ok {
return wrapScanError(src, x)
}
return json.Unmarshal(bytes, &x)
}
// ------------------------------------------------- --------------------------------------------------------------------