I'm trying to call the below MakeQuery(query string)
function by passing the string from Python using ctypes
module.
It works when I call it from Python as a function shared object with hardcoded arguments from Works()
in Go:
//export Works
func Works() {
newMod := MakeQuery(`SELECT TOP 3 NodeID FROM NCM.ConfigArchive`)
fmt.Println(newMod)
}
// Query db connection and return results as map
//export MakeQuery
func MakeQuery(query string) []map[string]interface {} {...}
According to some web tutorials, I need to convert it as such:
from ctypes import *
lib = cdll.LoadLibrary("./test.so")
query = "SELECT TOP 3 NodeID FROM NCM.ConfigArchive"
b_query = query.encode('utf-8')
lib.MakeQuery.argtypes = [c_char_p]
print lib.MakeQuery(b_query)
But it doesn't work due to some string type conversion error:
&{400 Bad Request 400 HTTP/1.1 1 1 map[Content-Length:[1602] Content-Type:
[application/json] Date:[Sat, 18 May 2019 12:48:54 GMT] Server:[Microsoft-
HTTPAPI/2.0]] 0xc00009a1c0 1602 [] false false map[] 0xc000104000 0xc0001a8000}
Would be a great help if someone can point me to the direction to convert Python's string type into Go in some way.