-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.go
81 lines (64 loc) · 1.27 KB
/
event.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
package config
import (
"strings"
)
// Event is a configuration event.
type Event int
const (
// GET Get key event
GET Event = iota
// SET Set key event
SET
// TOINT Convert to int event
TOINT
// TOSTRING Convert to string event
TOSTRING
// TOBOOL Convert to bool event
TOBOOL
// TOTIME Convert to time event
TOTIME
// SWAP Swap handler event
SWAP
// INIT Initialize handler event
INIT
// UNKNOWN Unknown event
UNKNOWN
)
// tostr maps events to their string representation.
var tostr = map[Event]string{
GET: "GET",
SET: "SET",
TOINT: "TOINT",
TOSTRING: "TOSTRING",
TOBOOL: "TOBOOL",
TOTIME: "TOTIME",
SWAP: "SWAP",
INIT: "INIT",
}
// String turns an event into a string.
func (e Event) String() string {
if val, found := tostr[e]; found {
return val
}
return "UNKNOWN"
}
// toevent maps strings to events
var toevent = map[string]Event{
"GET": GET,
"SET": SET,
"TOINT": TOINT,
"TOSTRING": TOSTRING,
"TOBOOL": TOBOOL,
"TOTIME": TOTIME,
"SWAP": SWAP,
"INIT": INIT,
"UNKNOWN": UNKNOWN,
}
// ToEvent maps a string to an event. The match on string is not
// case sensitive.
func ToEvent(str string) Event {
if val, found := toevent[strings.ToUpper(str)]; found {
return val
}
return UNKNOWN
}