-
Notifications
You must be signed in to change notification settings - Fork 0
/
host.go
165 lines (140 loc) · 4.63 KB
/
host.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package types
import (
"github.com/extism/go-pdk"
)
func StringBytePtr(msg string) uint64 {
mem := pdk.AllocateString(msg)
return mem.Offset()
}
func ByteArrPtr(arr []byte) uint64 {
mem := pdk.AllocateBytes(arr)
return mem.Offset()
}
func EmptyResult() int32 {
mem := pdk.AllocateString("{}")
pdk.OutputMemory(mem)
return 0
}
func TestResult() int32 {
mem := pdk.AllocateString(`{
"result": true
}`)
pdk.OutputMemory(mem)
return 0
}
func pointerToBytes(p uint64) []byte {
responseMemory := pdk.FindMemory(p)
buf := make([]byte, int(responseMemory.Length()))
responseMemory.Load(buf)
return buf
}
func pointerToString(p uint64) string {
responseMemory := pdk.FindMemory(p)
buf := make([]byte, int(responseMemory.Length()))
responseMemory.Load(buf)
return string(buf[:])
}
type LogLevel uint32
const (
LogLevelTrace LogLevel = iota
LogLevelDebug
LogLevelInfo
LogLevelWarn
LogLevelError
LogLevelCritical
LogLevelMax
)
func (bp LogLevel) String() string {
return []string{
"LogLevelTrace",
"LogLevelDebug",
"LogLevelInfo",
"LogLevelWarn",
"LogLevelError",
"LogLevelCritical",
"LogLevelMax",
}[bp]
}
type Status uint32
const (
StatusOK Status = iota
StatusNotFound
StatusBadArgument
StatusEmpty
StatusCasMismatch
StatusInternalFailure
StatusUnimplemented
)
func (bp Status) String() string {
return []string{
"StatusOK",
"StatusNotFound",
"StatusBadArgument",
"StatusEmpty",
"StatusCasMismatch",
"StatusInternalFailure",
"StatusUnimplemented",
}[bp]
}
//export proxy_log
func ProxyLog(logLevel LogLevel, messageData uint64, messageSize uint64) Status
//export proxy_log_event
func ProxyLogEvent(context uint64, contextSize uint64) Status
//export proxy_http_call
func ProxyHttpCall(context uint64, contextSize uint64) uint64
//export proxy_state
func GetProxyState(context uint64) uint64
//export proxy_state_value
func GetProxyStateValue(context uint64, contextSize uint64) uint64
//export proxy_cluster_state
func GetClusterState(context uint64) uint64
//export proxy_cluster_state_value
func GetClusterStateValue(context uint64, contextSize uint64) uint64
//export proxy_datastore_keys
func _ProxyDatastoreKeys(context uint64, contextSize uint64) uint64
//export proxy_datastore_get
func _ProxyDataStoreGet(context uint64, contextSize uint64) uint64
//export proxy_datastore_exists
func _ProxyDataStoreExists(context uint64, contextSize uint64) uint64
//export proxy_datastore_pttl
func _ProxyDataStorePttl(context uint64, contextSize uint64) uint64
//export proxy_datastore_setnx
func _ProxyDataStoreSetnx(context uint64, contextSize uint64) uint64
//export proxy_datastore_del
func _ProxyDataStoreDel(context uint64, contextSize uint64) uint64
//export proxy_datastore_incrby
func _ProxyDataStoreIncrby(context uint64, contextSize uint64) uint64
//export proxy_datastore_pexpire
func _ProxyDataStorePexpire(context uint64, contextSize uint64) uint64
//export proxy_datastore_all_matching
func _ProxyDataStoreAllMatching(context uint64, contextSize uint64) uint64
//export proxy_plugin_datastore_keys
func _ProxyPluginDatastoreKeys(context uint64, contextSize uint64) uint64
//export proxy_plugin_datastore_get
func _ProxyPluginDataStoreGet(context uint64, contextSize uint64) uint64
//export proxy_plugin_datastore_exists
func _ProxyPluginDataStoreExists(context uint64, contextSize uint64) uint64
//export proxy_plugin_datastore_pttl
func _ProxyPluginDataStorePttl(context uint64, contextSize uint64) uint64
//export proxy_plugin_datastore_setnx
func _ProxyPluginDataStoreSetnx(context uint64, contextSize uint64) uint64
//export proxy_plugin_datastore_del
func _ProxyPluginDataStoreDel(context uint64, contextSize uint64) uint64
//export proxy_plugin_datastore_incrby
func _ProxyPluginDataStoreIncrby(context uint64, contextSize uint64) uint64
//export proxy_plugin_datastore_pexpire
func _ProxyPluginDataStorePexpire(context uint64, contextSize uint64) uint64
//export proxy_plugin_datastore_all_matching
func _ProxyPluginDataStoreAllMatching(context uint64, contextSize uint64) uint64
//export proxy_plugin_map_set
func _ProxyPluginMapSet(context uint64, contextSize uint64) uint64
//export proxy_plugin_map_get
func _ProxyPluginMapGet(context uint64, contextSize uint64) uint64
//export proxy_plugin_map
func _ProxyPluginMap(_requiredUInt64 uint64) uint64
//export proxy_global_map_set
func _ProxyGlobalMapSet(context uint64, contextSize uint64) uint64
//export proxy_global_map_get
func _ProxyGlobalMapGet(context uint64, contextSize uint64) uint64
//export proxy_global_map
func _ProxyGlobalMap(_requiredUInt64 uint64) uint64