-
Notifications
You must be signed in to change notification settings - Fork 85
/
severity.go
59 lines (52 loc) · 1.06 KB
/
severity.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
package claircore
import (
"bytes"
"database/sql/driver"
"fmt"
)
type Severity uint
const (
Unknown Severity = iota
Negligible
Low
Medium
High
Critical
)
func (s *Severity) MarshalText() ([]byte, error) {
return []byte(s.String()), nil
}
func (s *Severity) UnmarshalText(b []byte) error {
// This depends on the contents of severity_string.go.
i := bytes.Index([]byte(_Severity_name), b)
if i == -1 {
return fmt.Errorf("unknown severity %q", string(b))
}
idx := uint8(i)
for n, off := range _Severity_index {
if idx == off {
*s = Severity(n)
return nil
}
}
panic("unreachable")
}
func (s Severity) Value() (driver.Value, error) {
return s.String(), nil
}
func (s *Severity) Scan(i interface{}) error {
switch v := i.(type) {
case []byte:
return s.UnmarshalText(v)
case string:
return s.UnmarshalText([]byte(v))
case int64:
if v >= int64(len(_Severity_index)-1) {
return fmt.Errorf("unable to scan Severity from enum %d", v)
}
*s = Severity(v)
default:
return fmt.Errorf("unable to scan Severity from type %T", i)
}
return nil
}