-
Notifications
You must be signed in to change notification settings - Fork 405
/
listeners.go
45 lines (37 loc) · 1.07 KB
/
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
package agent
import (
"context"
"github.com/fnproject/fn/api/models"
"github.com/fnproject/fn/fnext"
)
type callTrigger interface {
fireBeforeCall(context.Context, *models.Call) error
fireAfterCall(context.Context, *models.Call) error
}
func (a *agent) AddCallListener(listener fnext.CallListener) {
a.callListeners = append(a.callListeners, listener)
}
func (a *agent) fireBeforeCall(ctx context.Context, call *models.Call) error {
return fireBeforeCallFun(a.callListeners, ctx, call)
}
func (a *agent) fireAfterCall(ctx context.Context, call *models.Call) error {
return fireAfterCallFun(a.callListeners, ctx, call)
}
func fireBeforeCallFun(callListeners []fnext.CallListener, ctx context.Context, call *models.Call) error {
for _, l := range callListeners {
err := l.BeforeCall(ctx, call)
if err != nil {
return err
}
}
return nil
}
func fireAfterCallFun(callListeners []fnext.CallListener, ctx context.Context, call *models.Call) error {
for _, l := range callListeners {
err := l.AfterCall(ctx, call)
if err != nil {
return err
}
}
return nil
}