I have developed a pam module using the cgo. can not be converted to []string a ** char
func pam_sm_authenticate(pamh *C.pam_handle_t, flags C.int, argc C.int, argv **C.char) int { fmt.Println(C.GoString(*argv[0])) return 0 }
error is
invalid operation: argv[0] (type **C.char does not support indexing)
Please let me know if you know.
Cobbled together from the cgo wiki: https://github.com/golang/go/wiki/cgo#Turning_C_arrays_into_Go_slices.
import "C"
import "unsafe"
func GoStrings(argc C.int, argv **C.char) []string {
length := int(argc)
tmpslice := (*[1 << 30]*C.char)(unsafe.Pointer(argv))[:length:length]
gostrings := make([]string, length)
for i, s := range tmpslice {
gostrings[i] = C.GoString(s)
}
return gostrings
}