The snippet library.
Small, practical examples. Search by task or narrow things down below.
Join portable path components
Join portable path components using a complete Go program with explicit sample inputs.
Go✓ Tested
Join words with a separator
Join words with a separator using a complete Go program with explicit sample inputs.
Go✓ Tested
Limit the bytes read from a stream
Limit the bytes read from a stream using a complete Go program with explicit sample inputs.
Go✓ Tested
Look up a map entry
Look up a map entry using a complete Go program with explicit sample inputs.
Go✓ Tested
Map a command with switch
Map a command with switch using a complete Go program with explicit sample inputs.
Go✓ Tested
Measure a duration between instants
Measure a duration between instants using a complete Go program with explicit sample inputs.
Go✓ Tested
Mutate a struct through a pointer receiver
Mutate a struct through a pointer receiver using a complete Go program with explicit sample inputs.
Go✓ Tested
Name a fixed configuration value
Name a fixed configuration value using a complete Go program with explicit sample inputs.
Go✓ Tested
Observe context cancellation
Observe context cancellation using a complete Go program with explicit sample inputs.
Go✓ Tested
Parse a Boolean configuration value
Parse a Boolean configuration value using a complete Go program with explicit sample inputs.
Go✓ Tested
Parse a date with a Go layout
Parse a date with a Go layout using a complete Go program with explicit sample inputs.
Go✓ Tested
Parse a duration string
Parse a duration string using a complete Go program with explicit sample inputs.
Go✓ Tested