-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.go
68 lines (56 loc) · 1.05 KB
/
action.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
package ulist
import (
"database/sql/driver"
"errors"
)
type Action int
var ErrUnknownActionString = errors.New("unknown action string")
const (
// ordered, order is required for list.GetAction
Reject Action = iota
Mod
Pass
)
// implement sql.Scanner
func (a *Action) Scan(value interface{}) (err error) {
*a, err = ParseAction(value.(string))
return
}
// implement sql/driver.Valuer
func (a Action) Value() (driver.Value, error) {
return a.String(), nil
}
func ParseAction(s string) (Action, error) {
switch s {
case Reject.String():
return Reject, nil
case Mod.String():
return Mod, nil
case Pass.String():
return Pass, nil
default:
return Mod, ErrUnknownActionString
}
}
func (a Action) String() string {
switch a {
case Reject:
return "reject"
case Mod:
return "mod"
case Pass:
return "pass"
default:
return "<unknown>"
}
}
// helpers for templates
func (a Action) EqualsMod() bool {
return a == Mod
}
func (a Action) EqualsPass() bool {
return a == Pass
}
func (a Action) EqualsReject() bool {
return a == Reject
}