How to Use Callbacks in Go

Export Go functions to C using the //export directive to enable C code to call back into your Go program.

Use the //export directive above a function to make it callable from C code. The function must have no arguments or only C-compatible types, and its name in C will match the identifier following //export.

//export goCallback
func goCallback(p unsafe.Pointer) {
	// Handle C callback logic here
}

If you need to pass a Go function pointer to C, store the function in a map, pass an integer token to C, and retrieve the function inside the exported callback using that token.