From 4753979481326a7c2aee5d1c503b0b31d09ab41f Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 1 Feb 2018 23:05:46 +0100 Subject: [PATCH] golang binding prove of concept --- example/go/main.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 example/go/main.go diff --git a/example/go/main.go b/example/go/main.go new file mode 100644 index 000000000000..430e067019e7 --- /dev/null +++ b/example/go/main.go @@ -0,0 +1,26 @@ +package main + +// #cgo LDFLAGS: -ltdjson +// #include +import "C" +import ( + "log" + "unsafe" +) + +func td_send(client unsafe.Pointer, query *C.char) { + C.td_json_client_send(client, query) +} + +func td_receive(client unsafe.Pointer) string { + return C.GoString(C.td_json_client_receive(client, 1.0)) +} + +func main() { + var client unsafe.Pointer + client = C.td_json_client_create() + + query := C.CString(`{"@type": "getAuthorizationState"}`) + td_send(client, query) + log.Println(td_receive(client)) +}