Go Built-in Functions Reference

All Go built-in functions with signature, type constraints and panic conditions.

Searchable reference for Go's pre-declared built-in functions — make, new, len, cap, append, copy, delete, clear, close, min, max, panic, recover, complex, real, imag — each with signature, valid types, and panic conditions.

What is the difference between make and new in Go?

new(T) allocates zeroed storage and returns a pointer *T, working for any type. make(T) initializes the internal structure of slices, maps, and channels only, and returns the value T itself, not a pointer. Use make for those three reference types and new for everything else.

Go keeps its language small by providing a fixed set of pre-declared built-in functions that live in no package and cannot be imported or shadowed sensibly. They handle allocation, slicing, maps, channels, and panics. This tool is a searchable reference covering each built-in’s signature, the types it accepts, and exactly when it panics.

How it works

Built-ins are part of the language spec, not the standard library, so they need no import. Several are generic over many types (len, cap, append), while others are restricted to specific reference types (make, close, delete). The reference groups them by purpose:

  • Allocationmake (slices/maps/channels), new (any type, returns a pointer).
  • Sliceslen, cap, append, copy, clear.
  • Mapslen, delete, clear.
  • Channelsmake, len, cap, close.
  • Ordered valuesmin, max (Go 1.21+).
  • Errors/flowpanic, recover.
  • Complex numberscomplex, real, imag.

Worked example

s := make([]int, 0, 4) // len 0, cap 4
s = append(s, 1, 2, 3) // assign back: append may reallocate
n := copy(dst, s)      // n = number of elements copied (min of lengths)
delete(m, "key")       // no-op if key absent, never panics
close(ch)              // panics if ch is nil or already closed

The key habit is reassigning the result of append, because it may return a slice backed by a freshly allocated array.

Notes

  • len and cap are the only built-ins whose results can be constant when the argument is an array or array pointer with no side effects.
  • delete on a missing key is a safe no-op; it never panics.
  • panic unwinds the stack running deferred functions; a recover inside one of those deferred functions stops the unwinding and returns the panic value.
  • min, max, and clear require Go 1.21 or newer.