/
event.go
60 lines (51 loc) · 1.18 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
/*
* ECAL
*
* Copyright 2020 Matthias Ladkau. All rights reserved.
*
* This Source Code Form is subject to the terms of the MIT
* License, If a copy of the MIT License was not distributed with this
* file, You can obtain one at https://opensource.org/licenses/MIT.
*/
package engine
import (
"fmt"
"strings"
"github.com/krotik/common/stringutil"
)
/*
Event data structure
*/
type Event struct {
name string // Name of the event
kind []string // Kind of the event (dot notation expressed as array)
state map[interface{}]interface{} // Event state
}
/*
NewEvent returns a new event object.
*/
func NewEvent(name string, kind []string, state map[interface{}]interface{}) *Event {
return &Event{name, kind, state}
}
/*
Name returns the event name.
*/
func (e *Event) Name() string {
return e.name
}
/*
Kind returns the event kind.
*/
func (e *Event) Kind() []string {
return e.kind
}
/*
State returns the event state.
*/
func (e *Event) State() map[interface{}]interface{} {
return e.state
}
func (e *Event) String() string {
return fmt.Sprintf("Event: %v %v %v", e.name, strings.Join(e.kind, "."),
stringutil.ConvertToString(e.state))
}