package main import ( "fmt" "math" ) func main() { printNumericValue(1) // prints "int" printNumericValue("1") // prints "string" printNumericValue(struct{}{}) // prints "struct {}" } // Interfaces type shape interface { area() float64 perimeter() float64 } type rect struct { width, height float64 } func (r rect) area() float64 { return r.width * r.height } func (r rect) perimeter() float64 { return 2*r.width + 2*r.height } type circle struct { radius float64 } func (c circle) area() float64 { return math.Pi * c.radius * c.radius } func (c circle) perimeter() float64 { return 2 * math.Pi * c.radius } // Type Switches func printNumericValue(num interface{}) { switch v := num.(type) { case int: fmt.Printf("%T\n", v) case string: fmt.Printf("%T\n", v) default: fmt.Printf("%T\n", v) } }