at the first we would like to thank you for provide us a Go SDK for Cryptlex.
But I got problem when accessing Custom License Field with Go, it seems GetCustomLicenseField only accept C.char type (for fieldValue parameter), with C.char it’s going well, but I only got the first character. for example the value should be "my@email.com" but I only got “m”. here’s my code
var fieldValue C.char
C. GetCustomLicenseField(C.CString(“300”), &fieldValue, 256)
result for fieldValue is “m”
When I used bytes.Buffer, it’s goes errors, here’s my code
fieldValue := new(bytes.Buffer)
C. GetCustomLicenseField(C.CString(“300”), &fieldValue, 256)
result for field value is “Cannot use &fieldValue (type **bytes.Buffer) as type *C.char in argument…”
I used C.GoString to get value from a pointer, like code below:
var fieldValue C.char
var fieldName = C.CString("300")
status = C.GetCustomLicenseField(fieldName,&fieldValue, 256)
if (C.LA_OK == status) {
return C.GoString(&fieldValue)
}
But, I found another problem, I can’t free the memory of fieldName and fieldValue, I got panic error like this below when I trying to get CustomFields many times:
for i := 0; i < 1000; i++ { // running thousand times no panic
var fieldName = C.CString(“300”)
var fieldValue = [256]C.char{}
status = C.GetCustomLicenseField(fieldName, &fieldValue[0], 256)
if (C.LA_OK == status) {
fmt.Println("300: ", C.GoString(&fieldValue[0]))
}
}