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
Attach behavior to a struct
Attach behavior to a struct 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
Define related integer constants
Define related integer constants using a complete Go program with explicit sample inputs.
Go✓ Tested
Embed a struct for shared fields
Embed a struct for shared fields 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
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
Write a generic slice helper
Write a generic slice helper using a complete Go program with explicit sample inputs.
Go✓ Tested