Basic Types
Boolean Type
The set of boolean values:
true and falseInteger Types
Signed integer type that is at least 32 bits in size
Signed 8-bit integers. Range: -128 through 127
Signed 16-bit integers. Range: -32768 through 32767
Signed 32-bit integers. Range: -2147483648 through 2147483647
Signed 64-bit integers. Range: -9223372036854775808 through 9223372036854775807
Unsigned integer type that is at least 32 bits in size
Unsigned 8-bit integers. Range: 0 through 255
Unsigned 16-bit integers. Range: 0 through 65535
Unsigned 32-bit integers. Range: 0 through 4294967295
Unsigned 64-bit integers. Range: 0 through 18446744073709551615
Integer type large enough to hold the bit pattern of any pointer
Floating-Point Types
IEEE 754 32-bit floating-point numbers
IEEE 754 64-bit floating-point numbers
Complex numbers with float32 real and imaginary parts
Complex numbers with float64 real and imaginary parts
String and Character Types
Set of all strings of 8-bit bytes, conventionally but not necessarily representing UTF-8-encoded text. Strings are immutable.
Alias for uint8. Used to distinguish byte values from 8-bit unsigned integers.
Alias for int32. Used to distinguish character values from integer values.
Special Types
Alias for interface. Represents values of any type.
Interface implemented by all comparable types (booleans, numbers, strings, pointers, channels, arrays of comparable types, structs whose fields are all comparable types). May only be used as a type parameter constraint.
The conventional interface for representing an error condition, with nil representing no error.
Built-in Functions
Memory Allocation
Allocates and initializes an object of type slice, map, or channel. Returns the initialized object (not a pointer).
- Slice:
make([]int, length, capacity)- capacity is optional - Map:
make(map[string]int, initialSize)- size is optional - Channel:
make(chan int, bufferSize)- buffer size is optional (0 for unbuffered)
Allocates memory for a variable of the specified type, initializes it to its zero value, and returns a pointer to it.
Slice and Array Operations
Appends elements to the end of a slice. If capacity is insufficient, a new underlying array is allocated. Returns the updated slice.
Copies elements from source slice to destination slice. Returns the number of elements copied (minimum of len(src) and len(dst)). Source and destination may overlap.
Returns the length of v:
- Array: number of elements
- Slice/Map: number of elements (0 if nil)
- String: number of bytes
- Channel: number of queued elements (0 if nil)
Returns the capacity of v:
- Array: number of elements (same as len)
- Slice: maximum length when resliced (0 if nil)
- Channel: buffer capacity (0 if nil)
Map Operations
Deletes the element with the specified key from the map. If m is nil or the key doesn’t exist, delete is a no-op.
Channel Operations
Closes a channel. Should only be executed by the sender. After closing, receives will return the zero value without blocking.
Collection Operations
Clears maps and slices. For maps, deletes all entries. For slices, sets all elements up to the length to their zero value.
Comparison Functions
Returns the largest value of the arguments. Requires at least one argument. For floating-point types, returns NaN if any argument is NaN.
Returns the smallest value of the arguments. Requires at least one argument. For floating-point types, returns NaN if any argument is NaN.
Complex Number Functions
Constructs a complex value from two floating-point values (real and imaginary parts).
Returns the real part of the complex number c.
Returns the imaginary part of the complex number c.
Panic and Recovery
Stops normal execution of the current goroutine. Deferred functions still run. Calling panic with a nil value causes a run-time error.
Allows a program to manage panicking behavior. Only useful inside deferred functions. Returns the value passed to panic, or nil if not panicking.
Constants
Boolean constant representing true
Boolean constant representing false
Predeclared identifier representing the untyped integer ordinal number of the current const specification in a const declaration (zero-indexed).
Predeclared identifier representing the zero value for pointer, channel, func, interface, map, or slice types.