Cannot use CallBack (type func(*_Ctype_char, *_Ctype_char, _Ctype_ulong)) as type *[0]byte in argument to _Cfunc_reload_pattern_db


I am facing the following issue:

I have a GO code that has to be called from the C code:

var field_mappings map[string]string = map[string]string{
" A": “a”,
“B”: “b”,
“C”: “c”,
“D”: “d”}

//export CallBack
func CallBack(key *C.char, value *C.char, value_len C.size_t){

if remap, ok := field_mappings[key]; ok {
    fmt.Println(key, remap)


I am passing this callback method to the C function

func ReloadPatternDB(opts Y){

x := C.CString(opts.x)
C.reload_pattern_db(x, CallBack);


int reload_pattern_db(const gchar* filename, key_value_cb cb)



Following is my C header file:

#ifndef TEST_H
#define TEST_H

#include <stdlib.h>

typedef void (key_value_cb)(const char key, const char* value, size_t value_len);
int initialize_engine(const char* filename, const char* module_path, key_value_cb cb);
int reload_pattern_db(const char* filename, key_value_cb cb);
void match(const char* pattern, size_t pattern_len, const char* program, size_t program_len);


When I compile the GO code I am getting the following error:


./main.go:80:32: cannot use key (type _Ctype_char) as type string in map index
./main.go:91:21: cannot use CallBack (type func(
_Ctype_char, *_Ctype_char, _Ctype_ulong)) as type [0]byte in argument to _Cfunc_reload_pattern_db
./main.go:143:21: cannot use CallBack (type func(
_Ctype_char, *_Ctype_char, _Ctype_ulong)) as type *[0]byte in argument to

I am new to GO and CGO.Can someone please point out the error and help me out ?


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