The snippet library.
Small, practical examples. Search by task or narrow things down below.
Represent a set with empty structs
Represent a set with empty structs using a complete Go program with explicit sample inputs.
Go✓ Tested
Resolve a relative URL
Resolve a relative URL using a complete Go program with explicit sample inputs.
Go✓ Tested
Return a descriptive validation error
Return a descriptive validation error using a complete Go program with explicit sample inputs.
Go✓ Tested
Return two values from a function
Return two values from a function using a complete Go program with explicit sample inputs.
Go✓ Tested
Reverse slice order
Reverse slice order using a complete Go program with explicit sample inputs.
Go✓ Tested
Round down to a whole minute
Round down to a whole minute using a complete Go program with explicit sample inputs.
Go✓ Tested
Run cleanup when a function returns
Run cleanup when a function returns using a complete Go program with explicit sample inputs.
Go✓ Tested
Run your first Go program
Run your first Go program using a complete Go program with explicit sample inputs.
Go✓ Tested
Scan whitespace-separated tokens
Scan whitespace-separated tokens using a complete Go program with explicit sample inputs.
Go✓ Tested
Send a JSON HTTP response
Send a JSON HTTP response using a complete Go program with explicit sample inputs.
Go✓ Tested
Separate a filename extension
Separate a filename extension using a complete Go program with explicit sample inputs.
Go✓ Tested
Set and retrieve an HTTP header
Set and retrieve an HTTP header using a complete Go program with explicit sample inputs.
Go✓ Tested