aerospike-client-go
aerospike-client-go copied to clipboard
Accepting interface{} instead of []interface{} in BatchGetObjects
Version: v3.0+
What we have now:
BatchGetObjects(policy *BatchPolicy, keys []*Key, objects []interface{}) (found []bool, err error)
So, to get objects into []myStruct
one have to first get them into []interface{}
, then convert each interface{}
into myStruct
.
I suggest:
BatchGetObjects(policy *BatchPolicy, keys []*Key, objects interface{}) (found []bool, err error)
This way one can pass []myStruct
directly into BatchGetObjects
. Inside BatchGetObjects
reflect
package can be used to check whether a slice type of appropriate length is passed.
As this is a breaking change, I suppose it may be implemented v4.0+.
Makes sense. Will do.
Btw, I also think that accepting empty/nil slice and appending to it found object might be more convenient.
So that the final signature is the following:
BatchGetObjects(policy *BatchPolicy, keys []*Key, objects interface{}) error
That way package users won't have to iterate found []bool
slice to find out what was actually fetched.
Not sure this is the expected API from aerospike client though, but definitely this is the common pattern I've seen a lot.
That way you won't be able to reuse a pre-allocated slice.
you will be able, when truncating it to zero length. That way append won't allocate memory, but reuse underlying slice's capacity.
ah, you literally meant append. That won't work due to race condition. We can only set at index without race, not append.