The snippet library.
Small, practical examples. Search by task or narrow things down below.
Append to a slice
Append to a slice 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
Choose a branch with if and else
Choose a branch with if and else using a complete Go program with explicit sample inputs.
Go✓ Tested
Choose floating-point division
Choose floating-point division using a complete Go program with explicit sample inputs.
Go✓ Tested
Combine two Boolean conditions
Combine two Boolean conditions using a complete Go program with explicit sample inputs.
Go✓ Tested
Count Unicode code points
Count Unicode code points using a complete Go program with explicit sample inputs.
Go✓ Tested
Declare a fixed-size array
Declare a fixed-size array using a complete Go program with explicit sample inputs.
Go✓ Tested
Declare and update a variable
Declare and update a variable using a complete Go program with explicit sample inputs.
Go✓ Tested
Format a readable status message
Format a readable status message using a complete Go program with explicit sample inputs.
Go✓ Tested
Group fields in a struct
Group fields in a struct using a complete Go program with explicit sample inputs.
Go✓ Tested
Handle a failed conversion
Handle a failed conversion using a complete Go program with explicit sample inputs.
Go✓ Tested