- Notifications
You must be signed in to change notification settings - Fork1.2k
Description
Background
I added a small feature to a repositoryauthzed/spicedb#1942 that supports passingWithCredentialsJSON
to Spanner options. Since this is just library code, it simply forwards the option directly.
I discovered thatWithCredentialsJSON
doesn't work correctly with nil slice, as converting them to an empty slice results in invalid JSON. To address this issue, I submitted another PR:authzed/spicedb#1948.
Problem
I believe the issue lies in how theWithCredentialsJSON
function handles a nil slice within the option pattern, treating it as an empty slice.
For user code, I agree with that use case; we call the option as needed.
However, for library code, it's more ergonomic to forward options directly without needing to consider how to pass them in such cases.
Solution
We can skip nil slice for the value.
This way the library code can simply forward the option directly.
Additional context
It seems there aren't enough use cases for handling slices in the option pattern.
I am looking for other libraries that handle this case, but I have only found one.
- aws-sdk-go skips the nil slice