Type switches
Need to branch on multiple types? A type switch lets you do several type assertions in one clean construct.
switch v := i.(type) {
case T:
// here v has type T
case S:
// here v has type S
default:
// no match; here v has the same type as i
}
The syntax is like a type assertion — i.(type) — except you use the keyword type instead of a specific type name. In each case branch, v is automatically typed correctly.
Try it: do(true) hits the default case. Add a case bool: branch and see what happens.