-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathcoprocess_lua.go
75 lines (52 loc) · 1.42 KB
/
coprocess_lua.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
// +build coprocess
// +build lua
package main
/*
#cgo pkg-config: luajit
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "coprocess/sds/sds.h"
#include "coprocess/api.h"
#include "coprocess/lua/binding.h"
static void LuaInit() {
}
static struct CoProcessMessage* LuaDispatchHook(struct CoProcessMessage* object) {
struct CoProcessMessage* outputObject = malloc(sizeof *outputObject);
return outputObject;
}
*/
import "C"
import(
"unsafe"
"github.com/TykTechnologies/tyk/coprocess"
"github.com/Sirupsen/logrus"
)
// CoProcessName declares the driver name.
const CoProcessName string = "lua"
// LuaDispatcher implements a coprocess.Dispatcher
type LuaDispatcher struct {
coprocess.Dispatcher
}
// Dispatch takes a CoProcessMessage and sends it to the CP.
func (d *LuaDispatcher) Dispatch(objectPtr unsafe.Pointer) unsafe.Pointer {
var object *C.struct_CoProcessMessage
object = (*C.struct_CoProcessMessage)(objectPtr)
var newObjectPtr *C.struct_CoProcessMessage
newObjectPtr = C.LuaDispatchHook(object)
return unsafe.Pointer(newObjectPtr)
}
func LuaInit() {
C.LuaInit()
}
// NewCoProcessDispatcher wraps all the actions needed for this CP.
func NewCoProcessDispatcher() (dispatcher coprocess.Dispatcher, err error) {
LuaInit()
dispatcher, err = &LuaDispatcher{}, nil
if err != nil {
log.WithFields(logrus.Fields{
"prefix": "coprocess",
}).Error(err)
}
return dispatcher, err
}