Skip to content

Table of Contents

Exercises — Month 6 · Week 2 (Production: packaging, CI, config, shutdown)

Standard-library-only Go packages with table-driven tests. Run all:

go test ./exercises/month-06/week-2/...

Prompts

1. envconfig — 12-factor config loader

Parse a typed Config from a map[string]string (a testable stand-in for the environment). Apply defaults (PORT=8080, LOG_LEVEL=info, TIMEOUT=5s), require DATABASE_URL, validate the port range and the log-level allow-list, and report every problem at once with errors.Join.

  • Skills: strconv, time.ParseDuration, errors.Join, accumulate-and-validate.

2. secretsource*_FILE-first secret resolution

Implement Resolve(name, look, read) with precedence: <name>_FILE (read the file) beats inline <name> beats ErrNotProvided. Trim whitespace (secret files often end in \n). Also implement Redact that masks all but the last two characters for safe logging.

  • Skills: dependency injection for testability, strings.TrimSpace, sentinel errors with errors.Is, wrapping with %w.

3. drain — graceful-shutdown in-flight tracker

Implement a Tracker whose Begin() registers a unit of work and returns its done func, and whose Wait(ctx) blocks until all work drains or ctx is done, returning ctx.Err() (e.g. context.DeadlineExceeded) on timeout.

  • Skills: sync.WaitGroup, bridging a WaitGroup to select via a goroutine + channel, context-bounded waiting.

Results

Exercise Focus go test
envconfig typed config, fail-fast, errors.Join
secretsource *_FILE precedence, redaction, errors.Is
drain bounded graceful drain, WaitGroup+context