FIND YOUR NEXT FEW LINES

The snippet library.

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

125 snippets foundClear filters
GoErrors & validation

Parse an email address syntax

Parse an email address syntax using a complete Go program with explicit sample inputs.

Go✓ Tested
GoSlices & collections

Preallocate a slice’s capacity

Preallocate a slice’s capacity using a complete Go program with explicit sample inputs.

Go✓ Tested
GoJSON & encoding

Preserve a large JSON integer

Preserve a large JSON integer using a complete Go program with explicit sample inputs.

Go✓ Tested
GoConcurrency & cancellation

Protect a shared counter

Protect a shared counter using a complete Go program with explicit sample inputs.

Go✓ Tested
GoConcurrency & cancellation

Queue values in a buffered channel

Queue values in a buffered channel using a complete Go program with explicit sample inputs.

Go✓ Tested
GoConcurrency & cancellation

Range over a closed channel

Range over a closed channel using a complete Go program with explicit sample inputs.

Go✓ Tested
GoJSON & encoding

Read a big-endian integer from bytes

Read a big-endian integer from bytes using a complete Go program with explicit sample inputs.

Go✓ Tested
GoTesting & reusable helpers

Read a fixed-size stream prefix

Read a fixed-size stream prefix using a complete Go program with explicit sample inputs.

Go✓ Tested
GoHTTP & URLs

Read a named request cookie

Read a named request cookie using a complete Go program with explicit sample inputs.

Go✓ Tested
GoHTTP & URLs

Read a URL’s host and path

Read a URL’s host and path using a complete Go program with explicit sample inputs.

Go✓ Tested
GoHTTP & URLs

Read an HTTP query parameter

Read an HTTP query parameter using a complete Go program with explicit sample inputs.

Go✓ Tested
GoFiles & paths

Read from an in-memory filesystem

Read from an in-memory filesystem using a complete Go program with explicit sample inputs.

Go✓ Tested