The snippet library.
Small, practical examples. Search by task or narrow things down below.
Accept a small behavior interface
Accept a small behavior interface using a complete Go program with explicit sample inputs.
Go✓ Tested
Accept a variable number of arguments
Accept a variable number of arguments using a complete Go program with explicit sample inputs.
Go✓ Tested
Advance a calendar date
Advance a calendar date using a complete Go program with explicit sample inputs.
Go✓ Tested
Append to a slice
Append to a slice using a complete Go program with explicit sample inputs.
Go✓ Tested
Attach behavior to a struct
Attach behavior to a struct using a complete Go program with explicit sample inputs.
Go✓ Tested
Build text incrementally
Build text incrementally using a complete Go program with explicit sample inputs.
Go✓ Tested
Calculate a SHA-256 text digest
Calculate a SHA-256 text digest using a complete Go program with explicit sample inputs.
Go✓ Tested
Calculate a subtotal
Calculate a subtotal using a complete Go program with explicit sample inputs.
Go✓ Tested
Call a function with a return value
Call a function with a return value using a complete Go program with explicit sample inputs.
Go✓ Tested
Capture state in a closure
Capture state in a closure using a complete Go program with explicit sample inputs.
Go✓ Tested
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