Go Complete Reference Index

Select any item below to open its full syntax specification, parameters, and live example.

Go Tutorial

Type semantics

4 entries

Methods

1 entry

Literal

2 entries

Standard library / encoding/csv

1 entry

Function semantics

1 entry

Expression

1 entry

Generics

2 entries

Interfaces

1 entry

Error handling

6 entries
Custom error typesfunc (e *Failure) Error() string
An error type implements Error() string. Typed errors can carry structured information rather than forcing consumers to parse text; choose consistent pointer or value receivers and use errors.As for extraction. Example output: 'true 7'.
Deferred argument evaluationdefer f(x)
The function value and argument values are evaluated when the defer executes, while the call itself runs later. A closure can instead read a captured variable at execution time. Deferred calls execute in reverse registration order when the surrounding function returns or unwinds. Example output: '2\n1'.
Deferred changes to named resultsfunc f() (n int) { defer func(){n++}(); return 4 }
Return expressions assign named result variables before deferred functions execute. A deferred closure can modify those variables before the caller receives them. Use this deliberately rather than hiding ordinary return logic. Example output: '5'.
Error return contractsfunc f() (T, error)
The final error result conventionally indicates success with nil. On failure, document whether other results are usable; some APIs return partial data with a nonnil error. Do not assume every nonnil error implies no result. Example output: '0 true'.
Error trees and multiple causeserrors.Join(err1, err2)
A joined error can expose multiple underlying errors. Matching via errors.Is searches the error tree, whereas errors.Unwrap only calls the single-error Unwrap() error method and therefore does not traverse a joined error. Join ignores nil inputs. Example output: 'true true true'.
Error wrapping and matchingfmt.Errorf("context: %w", err)
Wrapping exposes an underlying error to errors.Is and errors.As. Only expose implementation errors as part of an API contract when callers may depend on them. Formatting with %v preserves text but does not wrap the error. Example output: 'true false'.

Struct semantics

1 entry

Showing 20 of 5270 entries

Go Reference & Cheat Sheet | ByteMind