Go Type Switch
Jump to navigation
Jump to search
Internal
Overview
A type switch is a new control structure introduced by Go and a generalization of the type assertion. While a type assertion checks whether a specific concrete type implements a given interface, the type switch generalizes this check for multiple options:
var i SomeInterface = &SomeImplementation{data: "test"}
switch v := i.(type) {
case *SomeImplementation:
...
case *SomeImplementationB:
...
}