FIND YOUR NEXT FEW LINES

The snippet library.

Small, practical examples. Search by task or narrow things down below.

125 snippets foundClear filters
GoSlices & collections

Find an item’s index

Find an item’s index using a complete Go program with explicit sample inputs.

Go✓ Tested
GoDates & times

Find the weekday for a date

Find the weekday for a date using a complete Go program with explicit sample inputs.

Go✓ Tested
GoGetting Started

Format a readable status message

Format a readable status message using a complete Go program with explicit sample inputs.

Go✓ Tested
GoDates & times

Format a UTC timestamp

Format a UTC timestamp using a complete Go program with explicit sample inputs.

Go✓ Tested
GoGetting Started

Group fields in a struct

Group fields in a struct using a complete Go program with explicit sample inputs.

Go✓ Tested
GoGetting Started

Handle a failed conversion

Handle a failed conversion using a complete Go program with explicit sample inputs.

Go✓ Tested
GoConcurrency & cancellation

Increment an atomic counter

Increment an atomic counter using a complete Go program with explicit sample inputs.

Go✓ Tested
GoConcurrency & cancellation

Initialize a resource only once

Initialize a resource only once using a complete Go program with explicit sample inputs.

Go✓ Tested
GoErrors & validation

Inspect a typed conversion error

Inspect a typed conversion error using a complete Go program with explicit sample inputs.

Go✓ Tested
GoFunctions & types

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
GoGetting Started

Inspect a value’s type

Inspect a value’s type using a complete Go program with explicit sample inputs.

Go✓ Tested
GoSlices & collections

Iterate over bounded chunks

Iterate over bounded chunks using a complete Go program with explicit sample inputs.

Go✓ Tested