builtin

Guided tour · Misc · pkg.go.dev →

Documentation-only package for the predeclared identifiers (len, cap, append, make, new, delete, panic, recover, any, error, ...). Always in scope.

Slices and maps

make / new / len / cap

s := make([]int, 3, 8) // len 3, cap 8
m := make(map[string]int, 16)
p := new(int)             // *int pointing to zero value
len(s); cap(s); len(m)

append / copy / clear / delete

s = append(s, 4, 5)
n := copy(dst, src)
clear(s)          // Go 1.21+: zero all elements
clear(m)          // empty map
delete(m, "key")

Channels and control flow

close / panic / recover

close(ch)
panic("boom")
defer func() { if r := recover(); r != nil { /* handled */ } }()

Numeric helpers

min / max (Go 1.21+)

min(3, 1, 2)     // 1
max(3.0, 1.0)    // 3.0

Predeclared types

Aliases

any          // alias for interface{}
error        // interface{ Error() string }
byte         // alias for uint8
rune         // alias for int32
comparable   // type constraint