Table of Contents

Go - Type

About

Type in Go

Rules

the rules are simple:

Declaration and scope

type name underlying-type

List

Type switch

See https://golang.org/doc/effective_go.html#type_switch

var t interface{}
t = functionOfSomeType()
switch t := t.(type) {
default:
    fmt.Printf("unexpected type %T\n", t)     // %T prints whatever type t has
case bool:
    fmt.Printf("boolean %t\n", t)             // t has type bool
case int:
    fmt.Printf("integer %d\n", t)             // t has type int
case *bool:
    fmt.Printf("pointer to boolean %t\n", *t) // t has type *bool
case *int:
    fmt.Printf("pointer to integer %d\n", *t) // t has type *int
}

Assertion

v, ok = x.( T) 

// check type but discard result
_, ok = x.( T)