Go Type Switch
Jump to navigation
Jump to search
Internal
Overview
A type switch is a new control structure introduced by Go.
Type assertion with switch
:
var i SomeInterface
i = TypeA{"A"}
switch v := i.(type) {
case TypeA:
fmt.Printf("TypeA: %v\n", v)
case TypeB:
fmt.Printf("TypeB: %v\n", v)
}