-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdispatcher.go
36 lines (27 loc) · 978 Bytes
/
dispatcher.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
package main
import (
"log"
"golang.org/x/net/context"
"github.com/TykTechnologies/tyk-protobuf/bindings/go"
)
// Dispatcher implementation
type Dispatcher struct{}
// Dispatch will be called on every request:
func (d *Dispatcher) Dispatch(ctx context.Context, object *coprocess.Object) (*coprocess.Object, error) {
log.Println("Receiving object:", object)
// We dispatch the object based on the hook name (as specified in the manifest file), these functions are in hooks.go:
switch object.HookName {
case "MyPreHook":
log.Println("MyPreHook is called!")
return MyPreHook(object)
case "MyAuthCheck":
log.Println("MyAuthCheck is called!")
return MyAuthCheck(object)
}
log.Println("Unknown hook: ", object.HookName)
return object, nil
}
// DispatchEvent will be called when a Tyk event is triggered:
func (d *Dispatcher) DispatchEvent(ctx context.Context, event *coprocess.Event) (*coprocess.EventReply, error) {
return &coprocess.EventReply{}, nil
}