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": 3 } So I have a golang code like this. type FirstOption struct { FieldA string `json:"fieldA,omitempty"` FieldB string `json:"fieldB,omitempty"` } type SecondOption struct { FieldA string `json:"fieldA,omitempty"` FieldC string `json:"fieldC,omitempty"` } I would normally do something like this: func (option string) FirstOption { //I know this line is bad because I might want to return SecondOption // Do request, unmarshall json to FirstOption or SecondOption depending on the option string variable } But I need to know if it's possible to return either FirstOption or SecondOption, haven't figure out if it's possible or not and can't find a good solution in Google. I could probably make a struct that actually mixes SecondOption and FirstOption using the omitempty keyword, but I'm not really fond of that solution. Thanks for the help, -- Jose -- 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.