-
Notifications
You must be signed in to change notification settings - Fork 0
/
statuses.go
executable file
·147 lines (118 loc) · 3.19 KB
/
statuses.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package helpermodels
// StatusType type of status
type StatusType string
// Status status for a collection
type Status struct {
State StatusType `json:"state" bson:"state"`
Message string `json:"message" bson:"message"`
}
// Statusable make something Status able
type Statusable interface {
SetDone()
SetNew()
SetScheduled()
SetFailed()
SetCanceled()
SetDeleted()
SetPaused()
SetDeleting()
SetActive()
GetStatus() StatusType
GetMessage() string
IsFinal() bool
IsValid() bool
}
const (
// StatusDone the thing is done
StatusDone = StatusType("done")
// StatusNew the thing is just created
StatusNew = StatusType("new")
// StatusScheduled the thing is scheduled (has a date when it will start)
StatusScheduled = StatusType("scheduled")
// StatusActive means the thing is active (has been consume)
StatusActive = StatusType("active")
// StatusFailed the thing failed and has an error
StatusFailed = StatusType("failed")
// StatusCanceled the thing has been canceled for some reason
StatusCanceled = StatusType("canceled")
// StatusPaused the thing has been paused for some reason
StatusPaused = StatusType("paused")
// StatusSkipped the thing has been skipped for some reason
StatusSkipped = StatusType("skipped")
// StatusDeleted the thing has been deleted for some reason
StatusDeleted = StatusType("deleted")
// StatusDeleting something that as been marked to be deleted
StatusDeleting = StatusType("deleting")
)
// ValidStatusTypes valid types of permissions
var ValidStatusTypes = map[StatusType]StatusType{
StatusDone: StatusDone,
StatusNew: StatusNew,
StatusScheduled: StatusScheduled,
StatusFailed: StatusFailed,
StatusCanceled: StatusCanceled,
StatusDeleted: StatusDeleted,
StatusDeleting: StatusDeleting,
StatusActive: StatusActive,
}
// NewStatus create new status
func NewStatus(status string) *Status {
return &Status{
State: StatusType(status),
}
}
// SetActive set status as active
func (s *Status) SetActive() {
s.State = StatusActive
}
// SetDone set the status as done
func (s *Status) SetDone() {
s.State = StatusDone
}
// SetNew set the status as New
func (s *Status) SetNew() {
s.State = StatusNew
}
// SetScheduled set the status as Scheduled
func (s *Status) SetScheduled() {
s.State = StatusScheduled
}
// SetFailed set the status as Failed
func (s *Status) SetFailed() {
s.State = StatusFailed
}
// SetCanceled set the status as Canceled
func (s *Status) SetCanceled() {
s.State = StatusCanceled
}
// SetDeleted set the status as Canceled
func (s *Status) SetDeleted() {
s.State = StatusDeleted
}
// SetPaused set the status as paused
func (s *Status) SetPaused() {
s.State = StatusPaused
}
// SetDeleting set element as deleting
func (s *Status) SetDeleting() {
s.State = StatusDeleting
}
// GetStatus Get the status
func (s *Status) GetStatus() StatusType {
return s.State
}
// GetMessage Get the message
func (s *Status) GetMessage() string {
return s.Message
}
// IsFinal Status is final
func (s *Status) IsFinal() bool {
return s.State == StatusDone ||
s.State == StatusDeleted ||
s.State == StatusCanceled
}
// IsValid permission is valid
func (s *Status) IsValid() bool {
_, ok := ValidStatusTypes[s.State]
return ok
}