Skip to content

Instantly share code, notes, and snippets.

@adamluzsi
Created May 5, 2018 08:03
Show Gist options
  • Save adamluzsi/4fb0feddba48e175441f254fc20de822 to your computer and use it in GitHub Desktop.
Save adamluzsi/4fb0feddba48e175441f254fc20de822 to your computer and use it in GitHub Desktop.
Golang interface sub type based switch
package x
// interface TYpe based switch
func handlerForInterface(handler interface{}) EventHandler {
switch v := handler.(type) {
case func(*Session, interface{}):
return interfaceEventHandler(v)
case func(*Session, *ChannelCreate):
return channelCreateEventHandler(v)
case func(*Session, *ChannelDelete):
return channelDeleteEventHandler(v)
case func(*Session, *ChannelPinsUpdate):
return channelPinsUpdateEventHandler(v)
case func(*Session, *ChannelUpdate):
return channelUpdateEventHandler(v)
case func(*Session, *Connect):
return connectEventHandler(v)
case func(*Session, *Disconnect):
return disconnectEventHandler(v)
// . . . 37 more cases below
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment