/
rule.go
47 lines (41 loc) · 764 Bytes
/
rule.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
package status
import (
"strings"
)
const (
defaultDescription = "Rivi completed processing rules"
defaultState = "failure"
unknownState = "error"
)
var (
states = []string{
"error",
"failure",
"pending",
"success",
}
searchState map[string]bool
)
type rule struct {
State string `mapstructure:"state"`
Description string `mapstructure:"description"`
}
func (r *rule) Defaults() {
if r.State == "" {
r.State = defaultState
} else {
search := strings.ToLower(r.State)
if _, ok := searchState[search]; !ok {
r.State = unknownState
}
}
if r.Description == "" {
r.Description = defaultDescription
}
}
func init() {
searchState = make(map[string]bool)
for _, s := range states {
searchState[s] = true
}
}