-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
coprocess: reimplement gateway bindings using ctypes
- Loading branch information
1 parent
49eae70
commit b820bc3
Showing
6 changed files
with
42 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import ctypes | ||
parent = ctypes.cdll.LoadLibrary(None) | ||
|
||
parent.TykGetData.argtypes = [ctypes.c_char_p] | ||
parent.TykGetData.restype = ctypes.c_char_p | ||
|
||
parent.TykStoreData.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_int] | ||
|
||
class TykGateway(): | ||
def log(message, level): | ||
message_p = ctypes.c_char_p(bytes(message, "utf-8")) | ||
level_p = ctypes.c_char_p(bytes(level, "utf-8")) | ||
parent.CoProcessLog(message_p, level_p) | ||
|
||
def log_error(message): | ||
message_p = ctypes.c_char_p(bytes(message, "utf-8")) | ||
level_p = ctypes.c_char_p(bytes("error", "utf-8")) | ||
parent.CoProcessLog(message_p, level_p) | ||
|
||
def get_data(key): | ||
key_p = ctypes.c_char_p(bytes(key, "utf-8")) | ||
return parent.TykGetData(key_p) | ||
|
||
def store_data(key, value, ttl): | ||
key_p = ctypes.c_char_p(bytes(key, "utf-8")) | ||
value_p = ctypes.c_char_p(bytes(value, "utf-8")) | ||
ttl_int = ctypes.c_int(ttl) | ||
parent.TykStoreData(key_p, value_p, ttl_int) | ||
|
||
def trigger_event(name, payload): | ||
name_p = ctypes.c_char_p(bytes(name, "utf-8")) | ||
payload_p = ctypes.c_char_p(bytes(payload, "utf-8")) | ||
parent.TykTriggerEvent(name_p, payload_p) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
// +build coprocess | ||
// +build !grpc | ||
|
||
package gateway | ||
|
||
import "C" | ||
|