-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.go
66 lines (54 loc) · 1.26 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
package chat
import (
"time"
"github.com/marcelbeumer/crispy-octo-goggles/chat/util/now"
)
// Event is the interface for all events
type Event interface {
// When returns time of the event.
// Important we define *something* more than interface{}
// for static analysis to work on *Struct{} vs Struct{}
When() time.Time
}
// EventMeta is a base struct for other events to include
// basic meta data that all events have
type EventMeta struct {
Time time.Time `json:"time"`
}
// When returns the time of the event.
func (e *EventMeta) When() time.Time {
return e.Time
}
// NewEventMetaNow returns EventMeta with time set to "now".
func NewEventMetaNow() *EventMeta {
return &EventMeta{
Time: now.Now(),
}
}
// EventConnected is (guaranteed) the first event sent when
// a new connection is made
type EventConnected struct {
EventMeta
Users []string `json:"users"`
}
type EventUserListUpdate struct {
EventMeta
Users []string `json:"users"`
}
type EventUserEnter struct {
EventMeta
Name string `json:"name"`
}
type EventUserLeave struct {
EventMeta
Name string `json:"name"`
}
type EventSendMessage struct {
EventMeta
Message string `json:"message"`
}
type EventNewMessage struct {
EventMeta
Sender string `json:"sender"`
Message string `json:"message"`
}