beware that mail.([]interface{}) will *panic* if what is in there is not a []interface{}. You should almost always use ", ok" form of type casting, i.e.
list, ok := mail.([]interface{}) if !ok { // return an error or something sane } // use list On Friday, August 12, 2016 at 2:41:26 PM UTC-4, Vasily Korytov wrote: > > Hi, > > I have an interface{} variable that can be either string or a list of > string (yes, that's bad design, I know). > > I need a []string to feed it to strings.Join (I need one string for > output). > > This way works, that is explicitly creating []string and copying each > element to it: > > var list []string > for _, v := range mail.([]interface{}) { > list = append(list, v.(string)) > } > rcpt = strings.Join(list, ", ") > > Have I overlooked something and there is a way to do it in a more graceful > and effective way? > > Thanks. > > -- > Vasily Korytov > https://chillum.github.io > -- 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.