The snippet library.
Small, practical examples. Search by task or narrow things down below.
Check a function with table-driven cases
Check a function with table-driven cases using a complete Go program with explicit sample inputs.
Go✓ Tested
Check whether bytes contain valid JSON
Check whether bytes contain valid JSON using a complete Go program with explicit sample inputs.
Go✓ Tested
Clamp a value to an allowed interval
Clamp a value to an allowed interval using a complete Go program with explicit sample inputs.
Go✓ Tested
Compare floats within a tolerance
Compare floats within a tolerance using a complete Go program with explicit sample inputs.
Go✓ Tested
Compare two byte buffers
Compare two byte buffers using a complete Go program with explicit sample inputs.
Go✓ Tested
Distinguish end-of-input from other errors
Distinguish end-of-input from other errors 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
Read a fixed-size stream prefix
Read a fixed-size stream prefix 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
Sort records by a selected field
Sort records by a selected field using a complete Go program with explicit sample inputs.
Go✓ Tested