- Remove //go:build red_gate tag from internal/web/handlers_test.go and internal/db/pool_test.go now that consumer symbols are about to exist - go mod tidy after real importers land (deferred from Plan 01-01 per Codex concern #1) — chi/v5, templ, pgx/v5, google/uuid now in require list - internal/db/pool.go: NewPool(ctx, dsn) builds a pgxpool.Pool with MaxConns=10, MinConns=1; no eager Ping (RESEARCH Pitfall 2) - internal/web/slog.go: NewSlogHandler returns JSON when env='production', text otherwise; pure helper, no slog.SetDefault side effect - internal/web/middleware.go: RequestIDMiddleware (UUIDv4 → ctx + X-Request-ID header), LoggerFromContext helper, SlogLoggerMiddleware factory using chi WrapResponseWriter; field allowlist per V7/T-01-09
23 lines
782 B
Go
23 lines
782 B
Go
package web
|
|
|
|
import (
|
|
"io"
|
|
"log/slog"
|
|
)
|
|
|
|
// NewSlogHandler returns a slog.Handler appropriate for the supplied
|
|
// environment. When env == "production" the returned handler emits
|
|
// machine-parseable JSON; for any other value (including the empty string
|
|
// and "development") the handler emits human-readable text. Both handlers
|
|
// are configured at slog.LevelInfo.
|
|
//
|
|
// The caller is responsible for wiring the returned handler into a
|
|
// slog.Logger (typically via slog.SetDefault) — this function is a pure
|
|
// helper and intentionally has no side effects.
|
|
func NewSlogHandler(env string, w io.Writer) slog.Handler {
|
|
opts := &slog.HandlerOptions{Level: slog.LevelInfo}
|
|
if env == "production" {
|
|
return slog.NewJSONHandler(w, opts)
|
|
}
|
|
return slog.NewTextHandler(w, opts)
|
|
}
|