This repository has been archived by the owner on Nov 23, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
event.go
97 lines (77 loc) · 2.12 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright © 2019 Developer Network, LLC
//
// This file is subject to the terms and conditions defined in
// file 'LICENSE', which is part of this source code package.
package engine
import (
"encoding/gob"
"strings"
)
func init() {
gob.Register(&Event{})
}
// Event indicates an atomizer event has taken
// place that is not categorized as an error
// Event implements the stringer interface but
// does NOT implement the error interface
type Event struct {
// Message from atomizer about this error
Message string `json:"message"`
// ElectronID is the associated electron instance
// where the error occurred. Empty ElectronID indicates
// the error was not part of a running electron instance.
ElectronID string `json:"electronID"`
// AtomID is the atom which was processing when
// the error occurred. Empty AtomID indicates
// the error was not part of a running atom.
AtomID string `json:"atomID"`
// ConductorID is the conductor which was being
// used for receiving instructions
ConductorID string `json:"conductorID"`
}
func (e *Event) Event() string {
return e.String()
}
func (e *Event) String() string {
if e == nil {
return ""
}
var joins []string
ids := e.ids()
if ids != "" {
joins = append(joins, "["+ids+"]")
}
// Add the message to part of the error
if e.Message != "" {
joins = append(joins, e.Message)
}
return strings.Join(joins, " ")
}
// ids returns the electron and atom ids as a combination string
func (e *Event) ids() string {
var ids []string
// Include the conductor id if it is part of the event
if e.ConductorID != "" {
ids = append(ids, "cid:"+e.ConductorID)
}
// Include the atom id if it is part of the event
if e.AtomID != "" {
ids = append(ids, "aid:"+e.AtomID)
}
// Include the electron id if it is part of the event
if e.ElectronID != "" {
ids = append(ids, "eid:"+e.ElectronID)
}
return strings.Join(ids, " | ")
}
// makeEvent creates a base event with only a message and
// a time
func makeEvent(msg string) *Event {
return &Event{
Message: msg,
}
}
// Validate determines if the event is valid
func (e *Event) Validate() bool {
return e.Message != ""
}