Go Examples

Browse Go examples

goSnippet

Benchmark With B.Loop

Replace the manual for-i-less-than-b.N loop with b.Loop on Go 1.24: iteration count, timer reset, and memory stats are handled automatically.

goSnippet

Varint Packs Signed Integers

Store signed integers in one to ten bytes with binary.PutVarint, and walk the buffer back with binary.Varint to recover each value and its width.

goSnippet

Channel Len Cap Queue Depth

len on a buffered channel reports pending items and cap reports capacity; a nil channel reports zero for both and blocks forever on receive.

goSnippet

Typed Keys Store Context Values

Attach request-scoped data with context.WithValue, keyed by an unexported struct type so package boundaries cannot collide and lookups stay type-safe.