I'd say your case isn't dissimilar to this one:
https://godoc.org/gopkg.in/mgo.v2#Iter.All

>From a brief glance at your code, I'd think that using interface{}
rather than []interface{}
is a reasonable approach. It could actually save the conversion to
[]interface{} completely
in some places (for example in the couchdb driver, the  "docs" field
could have the
typed slice as an argument rather than the []interface{}, because the
whole thing
is encoded to JSON)

  cheers,
    rog.

On 2 May 2017 at 19:12, Jonathan Hall <fli...@flimzy.com> wrote:
> I have a public API that takes `...interface{}` as an argument.  (For
> reference: https://godoc.org/github.com/flimzy/kivik#DB.BulkDocs )
>
> I'm considering changing this to instead take `interface{}` as an argument,
> then using reflection to:
>
>   - Validate that the underlying type is an array
>   - Convert to `[]interface{}` before using it internally
>
> The reason I'm considering the change is that the normal use-case for the
> function is on an array of specifically-typed documents, and converting to
> `[]interface{}` before every call is cumbersome, and redundant ~95%+ of the
> time.
>
> I'm wondering if I might be overlooking any obvious drawbacks to this
> approach.  Thus far, my hesitation comes from the following facts:
>
> - Using reflection to check that an argument is an array seems sloppy
> (although I've seen it before). It loses all benefits of compile-time
> checking
> - Using reflection for the conversion is presumably slower than doing the
> conversion in the caller.
>
> Are there other pros or cons I'm not considering that I should take into
> account when deciding how to proceed?
>
> Much thanks,
>
> -- Jonathan
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to