package config
import (
"io"
"gopkg.in/yaml.v3"
)
func DecodeStrict(r io.Reader, dst any) error {
dec := yaml.NewDecoder(r)
dec.KnownFields(true)
return dec.Decode(dst)
}
YAML configuration is convenient, but it’s also a footgun when typos silently get ignored. I enable KnownFields(true) so unknown keys cause an error, which turns “silent misconfig” into a fast failure. That is especially useful during refactors when fields are renamed. I also decode from an io.Reader so the same code works for local files, embedded config, or S3 objects. In production, I combine this with a strict schema-like struct and a validation step that enforces invariants (timeouts must be > 0, lists must be non-empty, etc.). The goal is to make config errors noisy and actionable, not mysterious. This pattern is small and dependency-light, but it saves a lot of time when debugging environment drift.
Related snips
package api
import (
"net/http"
"runtime/debug"
)
Expose build metadata for debugging deploys
export interface RetryOptions {
retries: number;
baseMs: number;
maxMs: number;
signal?: AbortSignal;
onRetry?: (attempt: number, delay: number, err: unknown) => void;
Exponential backoff with jitter for retries
package dbutil
import (
"context"
"github.com/jackc/pgconn"
Retry Postgres serialization failures with bounded attempts
package files
import (
"context"
"time"
Presigned S3 upload URLs (AWS SDK v2)
package deps
import (
"net"
"net/http"
"time"
HTTP client tuned for production: timeouts, transport, and connection reuse
package api
import (
"io"
"net/http"
"os"
Safe multipart uploads using temp files (bounded memory)
Share this code
Here's the card — post it anywhere.