-
Notifications
You must be signed in to change notification settings - Fork 4
/
available_events.go
58 lines (49 loc) · 1.19 KB
/
available_events.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
package cupti
import (
"encoding/json"
"sync"
"github.com/iancoleman/strcase"
"github.com/pkg/errors"
)
// easyjson:json
type Event struct {
Event int `json:"event,omitempty"`
ID int `json:"id,omitempty"`
DomainID int `json:"domain_id,omitempty"`
Name string `json:"name,omitempty"`
ShortDescription string `json:"short_description,omitempty"`
LongDescription string `json:"long_description,omitempty"`
Category string `json:"category,omitempty"`
}
// easyjson:json
type events []Event
var AvailableEvents events = nil
func loadAvailableEvents() {
bts, err := ReadFile("/event_mapping.json")
if err != nil {
panic(err)
}
var res events
err = json.Unmarshal(bts, &res)
if err != nil {
panic(err)
}
AvailableEvents = res
}
func initAvailableEvents() {
var once sync.Once
once.Do(loadAvailableEvents)
}
func GetAvailableEvents() events {
initAvailableEvents()
return AvailableEvents
}
func FindEventByName(s0 string) (Event, error) {
s := strcase.ToSnake(s0)
for _, event := range AvailableEvents {
if event.Name == s {
return event, nil
}
}
return Event{}, errors.Errorf("cannot find event with name %s", s0)
}