-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.go
37 lines (31 loc) · 835 Bytes
/
action.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
package plexhooks
import (
"github.com/acamilleri/go-plexhooks/plex"
)
// Action generic interface to create action
type Action interface {
Name() string
Execute(event plex.Event) error
}
// Actions list of Action by Event name
type Actions map[plex.Name][]Action
// NewActions return an initialize map to
// define actions to run on each event
func NewActions() *Actions {
actions := make(Actions)
return &actions
}
// Add define one action or multiple actions to run on Event
func (a *Actions) Add(hook plex.Name, actions ...Action) {
actionsList := *a
actionsList[hook] = append(actionsList[hook], actions...)
*a = actionsList
}
// GetByHook get actions by hook name
func (a *Actions) GetByHook(hook plex.Name) []Action {
actionsList := *a
if actions, ok := actionsList[hook]; ok {
return actions
}
return nil
}