aerospike-client-go: Using Client.GetObject fails with "interface conversion: interface {} is bool, not int"

I’m trying to use GetObject to marshal the bin data into a struct containing a handful of bool values. The error comes from the lines below in read_command_reflect.go, where value is apparently already a bool, so trying to convert it to an int fails.

case reflect.Bool:
	f.SetBool(value.(int) == 1)

I assume this could also happen with the other more complicated case reflect.Bool in the switch under the reflect.Ptr case further down.

When I replace the first bool case with the following, everything seems to work:

case reflect.Bool:
	switch v := value.(type) {
	case int:
		f.SetBool(int(v) == 1)

I’m not sure if this is an optimal solution, but I’m happy to put up a PR if it seems okay.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17

Most upvoted comments

It is a slippery slope, and that’s why there is no string conversion support of “T”, “F”, “TRUE”, “FALSE”, “Y”, “N”, etc to boolean. And believe me, I used to do these in dBase, FoxPro days so I actually thought about them. In this case, we need to keep compatibility between our clients.