On Wed, Feb 8, 2017 at 2:55 PM <[email protected]> wrote:

> Hello,
>
> I am having several structures with the same interface and I need to
> declare them based on an sql value. On some languages it is possible to do
> something like:
>
> variable struct_name="MyStruct"
> object:= new struct_name{}
>
> I was wondering if its possible to do something similar in Go? Otherwise
> I'm having a switch with a case for each different class and its not a very
> elegant solution.
>

This sounds like a similar question to something that people tended to ask
in Python forums. And the answer given there was "you actually don't want
this feature, you want a dictionary mapping names to X". I think the exact
same answer could be given here, where you would create a map from string
to your interface:

https://play.golang.org/p/WZclMY58AG

Justin


> Thanks.
>
> --
> 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 [email protected].
> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to