-
Notifications
You must be signed in to change notification settings - Fork 7
/
filter.go
64 lines (51 loc) · 1.18 KB
/
filter.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
package workflow
import "strconv"
func MakeFilter(filters ...RecordFilter) *recordFilters {
var rf recordFilters
for _, f := range filters {
f(&rf)
}
return &rf
}
type recordFilters struct {
byForeignID FilterValue
byStatus FilterValue
byRunState FilterValue
}
func (r recordFilters) ByForeignID() FilterValue {
return r.byForeignID
}
func (r recordFilters) ByStatus() FilterValue {
return r.byStatus
}
func (r recordFilters) ByRunState() FilterValue {
return r.byRunState
}
func makeFilterValue(value string) FilterValue {
return FilterValue{
Enabled: true,
Value: value,
}
}
type FilterValue struct {
Enabled bool
Value string
}
type RecordFilter func(filters *recordFilters)
func FilterByForeignID(val string) RecordFilter {
return func(filters *recordFilters) {
filters.byForeignID = makeFilterValue(val)
}
}
func FilterByStatus(status int64) RecordFilter {
return func(filters *recordFilters) {
i := strconv.FormatInt(status, 10)
filters.byStatus = makeFilterValue(i)
}
}
func FilterByRunState(rs RunState) RecordFilter {
return func(filters *recordFilters) {
i := strconv.FormatInt(int64(rs), 10)
filters.byRunState = makeFilterValue(i)
}
}