You can't call it directly. CGO does not play well with vararg functions on the C side.
Ideally, you could create a C wrapper which accepts a list of options you want to pass.
The C function should then expand that list into the variable arguments required by curl_easy_set_opt()
. But I am not sure if that is possible or how to go about doing it.
The signature for your Go function is also incorrect:
type Option C.CURLoption
func (e *Easy) SetOption(options ...Option) {
// 'options' is now accessible as a slice: []Option
// Turn this slice into a list of C.CURLoption pointers and pass it to
// your C wrapper.
if len(options) == 0 {
return // No use continuing.
}
// Here is one way to convert the option slice to a list
// that C can work with.
size := int(unsafe.Sizeof(options[0]))
list := C.malloc(C.size_t(size * len(options)))
defer C.free(unsafe.Pointer(list)) // Free this after use!
for i := range options {
ptr := unsafe.Pointer( uintptr(list) + uintptr(size * i) )
*(*C.CURLoption)(ptr) = C.CURLoption(options[i])
}
C.my_setopt_wrapper(e.curl, list, C.int(len(options)))
}
Note that the type of the option parameter has been changed to a go version of it. When someone uses your package, they have no access to the C.xxx types. So you should not use those in your public api. They are only meant for internal use in your package.