-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_listeners.go
87 lines (77 loc) · 2.25 KB
/
app_listeners.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
package server
import (
"context"
"github.com/iron-io/functions/api/models"
)
type AppListener interface {
// BeforeAppCreate called right before creating App in the database
BeforeAppCreate(ctx context.Context, app *models.App) error
// AfterAppCreate called after creating App in the database
AfterAppCreate(ctx context.Context, app *models.App) error
// BeforeAppUpdate called right before updating App in the database
BeforeAppUpdate(ctx context.Context, app *models.App) error
// AfterAppUpdate called after updating App in the database
AfterAppUpdate(ctx context.Context, app *models.App) error
// BeforeAppDelete called right before deleting App in the database
BeforeAppDelete(ctx context.Context, app *models.App) error
// AfterAppDelete called after deleting App in the database
AfterAppDelete(ctx context.Context, app *models.App) error
}
// AddAppCreateListener adds a listener that will be notified on App created.
func (s *Server) AddAppListener(listener AppListener) {
s.appListeners = append(s.appListeners, listener)
}
func (s *Server) FireBeforeAppCreate(ctx context.Context, app *models.App) error {
for _, l := range s.appListeners {
err := l.BeforeAppCreate(ctx, app)
if err != nil {
return err
}
}
return nil
}
func (s *Server) FireAfterAppCreate(ctx context.Context, app *models.App) error {
for _, l := range s.appListeners {
err := l.AfterAppCreate(ctx, app)
if err != nil {
return err
}
}
return nil
}
func (s *Server) FireBeforeAppUpdate(ctx context.Context, app *models.App) error {
for _, l := range s.appListeners {
err := l.BeforeAppUpdate(ctx, app)
if err != nil {
return err
}
}
return nil
}
func (s *Server) FireAfterAppUpdate(ctx context.Context, app *models.App) error {
for _, l := range s.appListeners {
err := l.AfterAppUpdate(ctx, app)
if err != nil {
return err
}
}
return nil
}
func (s *Server) FireBeforeAppDelete(ctx context.Context, app *models.App) error {
for _, l := range s.appListeners {
err := l.BeforeAppDelete(ctx, app)
if err != nil {
return err
}
}
return nil
}
func (s *Server) FireAfterAppDelete(ctx context.Context, app *models.App) error {
for _, l := range s.appListeners {
err := l.AfterAppDelete(ctx, app)
if err != nil {
return err
}
}
return nil
}