Re: [go-nuts] Return different structs

2016-06-30 Thread Jose Bogarin Solano
Simon, Thanks for the information. Ordering the book at this moment. On 30 June 2016 at 02:35, Simon Ritchie wrote: > By the way, this is covered by in Donovan & Kernighan's new book The Go > Programming Language. On pages 197 and 198 of the first edition, they > describe an interface Expr,

Re: [go-nuts] Return different structs

2016-06-30 Thread Simon Ritchie
By the way, this is covered by in Donovan & Kernighan's new book The Go Programming Language. On pages 197 and 198 of the first edition, they describe an interface Expr, representing an expression, then five concrete types that satisfy that interface and contain different sorts of expressions a

Re: [go-nuts] Return different structs

2016-06-29 Thread jbogarin
On Wednesday, 29 June 2016 15:24:41 UTC-6, Shawn Milochik wrote: > > I'm thinking about something like this: > > https://play.golang.org/p/Aq8US0M-Fe > > I just used Stringer, but you could of course just create your own > interface with a function you find useful instead. > > Shaw, Thanks for

Re: [go-nuts] Return different structs

2016-06-29 Thread Shawn Milochik
I'm thinking about something like this: https://play.golang.org/p/Aq8US0M-Fe I just used Stringer, but you could of course just create your own interface with a function you find useful instead. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. T

Re: [go-nuts] Return different structs

2016-06-29 Thread Jose Bogarin Solano
Shawn, Thanks, I'll have to see how I can make that interface. Thanks for the guidance. On 29 June 2016 at 13:42, Shawn Milochik wrote: > You're welcome. I think that using empty interfaces isn't the best way to > do it. I meant (but didn't specify) that you should make an interface that > both

Re: [go-nuts] Return different structs

2016-06-29 Thread Shawn Milochik
You're welcome. I think that using empty interfaces isn't the best way to do it. I meant (but didn't specify) that you should make an interface that both of your struct types satisfy, and return those instead. -- You received this message because you are subscribed to the Google Groups "golang-n

Re: [go-nuts] Return different structs

2016-06-29 Thread jbogarin
Shawn, Thanks, it was an error on my side. The function actually returns an array of structs but an interface is not an array, so when I tried to return an array of interfaces, it crashed. I changed it from []interface{} to interface{} and it's working. Thanks for the help. On Tuesday, 28 Jun

Re: [go-nuts] Return different structs

2016-06-28 Thread Shawn Milochik
You could return an interface, or a []byte. -- 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 http

[go-nuts] Return different structs

2016-06-28 Thread jbogarin
Hello, I'm having a hard time figuring out if it's possible to return a function but having different structs as the return type. I'm talking to a REST API that does something like this: GET /endpoint?option=1 { "fieldA": 1, "fieldB": 2 } GET /endpoint?option=2 { "fieldA": 1, "fieldC":