FIND YOUR NEXT FEW LINES

The snippet library.

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

125 snippets foundClear filters
GoFiles & paths

Join portable path components

Join portable path components using a complete Go program with explicit sample inputs.

Go✓ Tested
GoStrings & text

Join words with a separator

Join words with a separator using a complete Go program with explicit sample inputs.

Go✓ Tested
GoTesting & reusable helpers

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

Look up a map entry

Look up a map entry using a complete Go program with explicit sample inputs.

Go✓ Tested
GoGetting Started

Map a command with switch

Map a command with switch using a complete Go program with explicit sample inputs.

Go✓ Tested
GoDates & times

Measure a duration between instants

Measure a duration between instants using a complete Go program with explicit sample inputs.

Go✓ Tested
GoFunctions & types

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

Name a fixed configuration value

Name a fixed configuration value using a complete Go program with explicit sample inputs.

Go✓ Tested
GoConcurrency & cancellation

Observe context cancellation

Observe context cancellation using a complete Go program with explicit sample inputs.

Go✓ Tested
GoErrors & validation

Parse a Boolean configuration value

Parse a Boolean configuration value using a complete Go program with explicit sample inputs.

Go✓ Tested
GoDates & times

Parse a date with a Go layout

Parse a date with a Go layout using a complete Go program with explicit sample inputs.

Go✓ Tested
GoDates & times

Parse a duration string

Parse a duration string using a complete Go program with explicit sample inputs.

Go✓ Tested