Python wrapper to GO library

Hi,

I’m trying to use a go library from my python project. For that, I need a ctypes equivalent to the arguments types. For example, for a string variable is quite straightforward and there are multiple examples online.

I simply use (from my python code):

class GoString(Structure):
    _fields_ = [("p", c_char_p), ("n", c_longlong)]

cmd_str = b"issue"
cmd = GoString(cmd_str, len(cmd_str))

BUT, for a variable of type map[string]string. I couldn’t figure it out. Does anyone has already mapped a map[string]string variable to python ctypes struct?

Thanks!

Compiled as a .so and accessed through ctypes I presume?

A map is quite a complicated type - it is defined in runtime/map.go in the go source.

I don’t think I’d attempt to use it directly from python, I’d write a wrapper in go and expose methods like Keys, Values, Get, Set for a given map which you can call from python.

Thanks for the suggested workaround! I’ll go this way then… thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.