multiple return values
A Go function returning more than one result at once, most often a useful value together with an error.
In more detail
The caller receives both, as in value, err := divide(10, 2), and must check err before trusting value. This keeps failures visible at every call instead of hidden in exceptions. Use the blank identifier _ for a result you deliberately ignore.
Example
pct, err := usage(200, 164)Related terms
- error — In Go, an ordinary value of the built-in error type that a function returns to report that something went wrong.
- short variable declaration — The := form that declares a new variable and sets its value in one step, letting Go infer the type.
- blank identifier — The underscore _ used in place of a variable name to throw away a value you do not need.
Taught in
- Installing the Go Toolchain — Concurrent Systems Programming with Go
- Your First Program and go run — Concurrent Systems Programming with Go
- Errors as Values — Concurrent Systems Programming with Go
- Files and the os Package — Concurrent Systems Programming with Go