On Fri, Dec 15, 2017 at 5:20 PM, jakdept <jakd...@gmail.com> wrote:

> So, I've thought about this further - if I don't bother with the
> interfaces, I can make this simpler. I can convert between with just
> v1csv(object) just fine. And that . should work because it'll only be used
> in a client, and it should still be extendable.
>
> It would still be nice to store those struct types in an array/map
> somehow. And that's the part where I'm still stuck. :/
>

you can do something like that:

 https://play.golang.org/p/SqAOa2-9Fa

ie: register constructor functions for the different types.
the advantage is that you can pass state or arguments to these constructor
functions.

if you don't need state, or if the zero value of your types will *always*
be sufficient, then, this could work for you:
https://play.golang.org/p/c0cMxKTt3S

(I would go with the former version instead of the latter: it's more
explicit and doesn't involve reflect as much)

hth,
-s

-- 
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