Go Type Switch

From NovaOrdis Knowledge Base
Revision as of 23:27, 13 August 2024 by Ovidiu (talk | contribs) (→‎Internal)
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)
}