nil
The Go value meaning nothing or not set, which is the zero value for pointers, slices, maps, channels, functions, interfaces and errors.
In more detail
A nil error means success. Reading from a nil slice or nil map is safe, but writing to a nil map or following a nil pointer makes the program panic. Compare with nil, as in if value == nil, before using optional data.
Example
if value == nil {
fmt.Println("unset")
}Related terms
- zero value — The value Go gives a variable automatically when you declare it without one: 0 for numbers, "" for strings, false for booleans and nil for pointers, slices and maps.
- pointer — A value that stores the memory location of another piece of data, so the program can follow it to that data.
- nil pointer dereference — Trying to follow a pointer that is nil, which makes a Go program panic with an invalid memory address error.
- error — In Go, an ordinary value of the built-in error type that a function returns to report that something went wrong.
- map — A Go collection that stores values by key, such as service name to port number, and looks them up quickly.
Taught in
- Your First Program and go run — Concurrent Systems Programming with Go
- Variables, Typing, and Zero Values — Concurrent Systems Programming with Go
- Pointers and Memory — Concurrent Systems Programming with Go
- Arrays, Slices, and Maps — Concurrent Systems Programming with Go
- Type Assertions and the Empty Interface — Concurrent Systems Programming with Go
- Errors as Values — Concurrent Systems Programming with Go
- The Standard testing Package — Concurrent Systems Programming with Go
- Calling APIs with net/http Client — Concurrent Systems Programming with Go