The snippet library.
Small, practical examples. Search by task or narrow things down below.
Parse an email address syntax
Parse an email address syntax using a complete Go program with explicit sample inputs.
Go✓ Tested
Preallocate a slice’s capacity
Preallocate a slice’s capacity using a complete Go program with explicit sample inputs.
Go✓ Tested
Preserve a large JSON integer
Preserve a large JSON integer using a complete Go program with explicit sample inputs.
Go✓ Tested
Protect a shared counter
Protect a shared counter using a complete Go program with explicit sample inputs.
Go✓ Tested
Queue values in a buffered channel
Queue values in a buffered channel using a complete Go program with explicit sample inputs.
Go✓ Tested
Range over a closed channel
Range over a closed channel using a complete Go program with explicit sample inputs.
Go✓ Tested
Read a big-endian integer from bytes
Read a big-endian integer from bytes using a complete Go program with explicit sample inputs.
Go✓ Tested
Read a fixed-size stream prefix
Read a fixed-size stream prefix using a complete Go program with explicit sample inputs.
Go✓ Tested
Read a named request cookie
Read a named request cookie using a complete Go program with explicit sample inputs.
Go✓ Tested
Read a URL’s host and path
Read a URL’s host and path using a complete Go program with explicit sample inputs.
Go✓ Tested
Read an HTTP query parameter
Read an HTTP query parameter using a complete Go program with explicit sample inputs.
Go✓ Tested
Read from an in-memory filesystem
Read from an in-memory filesystem using a complete Go program with explicit sample inputs.
Go✓ Tested