FIND YOUR NEXT FEW LINES

The snippet library.

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

125 snippets foundClear filters
GoMaps & sets

Represent a set with empty structs

Represent a set with empty structs using a complete Go program with explicit sample inputs.

Go✓ Tested
GoHTTP & URLs

Resolve a relative URL

Resolve a relative URL using a complete Go program with explicit sample inputs.

Go✓ Tested
GoErrors & validation

Return a descriptive validation error

Return a descriptive validation error using a complete Go program with explicit sample inputs.

Go✓ Tested
GoGetting Started

Return two values from a function

Return two values from a function using a complete Go program with explicit sample inputs.

Go✓ Tested
GoSlices & collections

Reverse slice order

Reverse slice order using a complete Go program with explicit sample inputs.

Go✓ Tested
GoDates & times

Round down to a whole minute

Round down to a whole minute using a complete Go program with explicit sample inputs.

Go✓ Tested
GoGetting Started

Run cleanup when a function returns

Run cleanup when a function returns using a complete Go program with explicit sample inputs.

Go✓ Tested
GoGetting Started

Run your first Go program

Run your first Go program using a complete Go program with explicit sample inputs.

Go✓ Tested
GoTesting & reusable helpers

Scan whitespace-separated tokens

Scan whitespace-separated tokens using a complete Go program with explicit sample inputs.

Go✓ Tested
GoHTTP & URLs

Send a JSON HTTP response

Send a JSON HTTP response using a complete Go program with explicit sample inputs.

Go✓ Tested
GoFiles & paths

Separate a filename extension

Separate a filename extension using a complete Go program with explicit sample inputs.

Go✓ Tested
GoHTTP & URLs

Set and retrieve an HTTP header

Set and retrieve an HTTP header using a complete Go program with explicit sample inputs.

Go✓ Tested