Go Examples

goSnippet

Fixed Worker Pool

Process a stream of jobs with a fixed number of goroutines, bounded channels and graceful completion.

goSnippet

Gin JWT Claims Middleware

Extract and verify JWT claims in Gin middleware, checking issuer and role before handlers, with claims injected into context.

goSnippet

Slog Structured Logging JSON

Adopt Go structured logging with slog: leveled JSON handlers, grouped attributes, log record routing, and child loggers with bound context.

goSnippet

Structured Logging With slog

Emit structured logs with the standard slog package so records carry typed key-value attributes that are easy to filter and correlate.

goSnippet

Table Driven Unit Test Go

Cover function branches with table-driven tests: declarative cases with names, parallel subtests, and precise failure output.

goSnippet

Env File Parser

Parse dotenv files with export prefixes, quoted values, inline comments, and strict key validation, returning a plain map.