The snippet library.
Small, practical examples. Search by task or narrow things down below.
Find an item’s index
Find an item’s index using a complete Go program with explicit sample inputs.
Go✓ Tested
Find the weekday for a date
Find the weekday for a date using a complete Go program with explicit sample inputs.
Go✓ Tested
Format a readable status message
Format a readable status message using a complete Go program with explicit sample inputs.
Go✓ Tested
Format a UTC timestamp
Format a UTC timestamp using a complete Go program with explicit sample inputs.
Go✓ Tested
Group fields in a struct
Group fields in a struct using a complete Go program with explicit sample inputs.
Go✓ Tested
Handle a failed conversion
Handle a failed conversion using a complete Go program with explicit sample inputs.
Go✓ Tested
Increment an atomic counter
Increment an atomic counter using a complete Go program with explicit sample inputs.
Go✓ Tested
Initialize a resource only once
Initialize a resource only once using a complete Go program with explicit sample inputs.
Go✓ Tested
Inspect a typed conversion error
Inspect a typed conversion error using a complete Go program with explicit sample inputs.
Go✓ Tested
Inspect a value with a type switch
Inspect a value with a type switch using a complete Go program with explicit sample inputs.
Go✓ Tested
Inspect a value’s type
Inspect a value’s type using a complete Go program with explicit sample inputs.
Go✓ Tested
Iterate over bounded chunks
Iterate over bounded chunks using a complete Go program with explicit sample inputs.
Go✓ Tested