Created
May 5, 2018 08:03
-
-
Save adamluzsi/4fb0feddba48e175441f254fc20de822 to your computer and use it in GitHub Desktop.
Golang interface sub type based switch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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