-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
93 lines (78 loc) · 1.93 KB
/
store.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
82
83
84
85
86
87
88
89
90
91
92
93
package chessclock
import (
"errors"
"github.com/OpenPeeDeeP/chessclock/chessclock"
)
//EventType is the type of event that is being parsed
type EventType int
const (
//ETStart is a start event
ETStart EventType = 1 + iota
//ETStop is a stop event
ETStop
)
//Eventer is any type that is an event
type Eventer interface{}
//Event is an event in the logs
type Event struct {
Type EventType
Details Eventer
}
func createStartEvent(startEvent *StartEvent) *Event {
return &Event{
Type: ETStart,
Details: startEvent,
}
}
func createStopEvent(stopEvent *StopEvent) *Event {
return &Event{
Type: ETStop,
Details: stopEvent,
}
}
//MustGetStartDetails returns the details for a start event.
//Panics if it is not a start event.
func (e *Event) MustGetStartDetails() *StartEvent {
start, ok := e.Details.(*StartEvent)
if !ok {
panic(errors.New("Event is not a start event"))
}
return start
}
//MustGetStopDetails returns the details for a stop event.
//Panics if it is not a stop event.
func (e *Event) MustGetStopDetails() *StopEvent {
stop, ok := e.Details.(*StopEvent)
if !ok {
panic(errors.New("Event is not a stop event"))
}
return stop
}
//IsStart returns true if the event is a start event
func (e *Event) IsStart() bool {
_, ok := e.Details.(*StartEvent)
return ok
}
//IsStop returns true if the event is a stop event
func (e *Event) IsStop() bool {
_, ok := e.Details.(*StopEvent)
return ok
}
//StartEvent details for a start event
type StartEvent struct {
StartTime int64
Tag string
Description string
}
//StopEvent details for a stop event
type StopEvent struct {
StopTime int64
Reason chessclock.StopRequest_Reason
}
//Storer is any type that can store the event logs and return them
type Storer interface {
Start(timestamp int64, tag, description string) error
Stop(timestamp int64, reason chessclock.StopRequest_Reason) error
TimeSheets() ([]int64, error)
Events(date int64) ([]*Event, error)
}