vendredi 28 avril 2017

go: or inside condition

I have this code:

if ev, ok := evt.(*ATypeEvent); ok {
   //process ATypeEvent
} else if ev, ok := evt.(*BTypeEvent); ok {
   //process BTypeEvent
} else if ev, ok := evt.(*CTypeEvent); ok {
   //process CTypeEvent
}

It so now happens that I have 3 more event types, which all fit into one of the other 3 - I'd think I need a an OR.

But after several tries, I haven't been able to figure how to do it. This doesn't work:

if ev, ok := evt.(*ATypeEvent) || evt.(*XTypeEvent); ok {
   //process ATypeEvent and X
} else if ev, ok := evt.(*BTypeEvent)  || evt.(*YTypeEvent); ok {
   //process BTypeEvent and Y
} else if ev, ok := evt.(*CTypeEvent)  || evt.(*ZTypeEvent); ok {
   //process CTypeEvent and Z
}

nor something like

if ev, ok := evt.(*ATypeEvent) || ev, ok := evt.(*XTypeEvent); ok {

nor

if ev, ok := (evt.(*ATypeEvent) || evt.(*XTypeEvent ) ); ok {

How can this be done correctly?

Aucun commentaire:

Enregistrer un commentaire