diff options
author | Valery Piashchynski <[email protected]> | 2021-10-30 14:56:35 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-10-30 14:56:35 +0300 |
commit | 875f0060501fa3f32b21c1670aeb5efe15a37e24 (patch) | |
tree | af01ea1a12f071250b97f64f31f1cc98378d40ce /events/types.go | |
parent | c8c3f9f113eae13aa37cf92043b288bb0c68a622 (diff) |
Add docs, update tests
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'events/types.go')
-rw-r--r-- | events/types.go | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/events/types.go b/events/types.go index 65a76d15..806e81ce 100644 --- a/events/types.go +++ b/events/types.go @@ -1,5 +1,9 @@ package events +import ( + "fmt" +) + type EventBus interface { SubscribeAll(subID string, ch chan<- Event) error SubscribeP(subID string, pattern string, ch chan<- Event) error @@ -10,14 +14,14 @@ type EventBus interface { } type Event interface { + Type() fmt.Stringer Plugin() string - Type() EventType Message() string } -type RREvent struct { +type event struct { // event typ - typ EventType + typ fmt.Stringer // plugin plugin string // message @@ -25,22 +29,26 @@ type RREvent struct { } // NewEvent initializes new event -func NewEvent(t EventType, plugin string, msg string) *RREvent { - return &RREvent{ +func NewEvent(t fmt.Stringer, plugin string, message string) *event { + if t.String() == "" || plugin == "" { + return nil + } + + return &event{ typ: t, plugin: plugin, - message: msg, + message: message, } } -func (r *RREvent) Type() EventType { +func (r *event) Type() fmt.Stringer { return r.typ } -func (r *RREvent) Message() string { +func (r *event) Message() string { return r.message } -func (r *RREvent) Plugin() string { +func (r *event) Plugin() string { return r.plugin } |