fix: validate config after PostLoad hooks

Re-run validator after PostLoad, return errors from RootDir, and add Config
alias for C(). Hooks receive *T instead of *Manager.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-29 18:00:31 -07:00
parent 444b2d4cf4
commit f2b6c07ff7
9 changed files with 421 additions and 230 deletions
+20
View File
@@ -0,0 +1,20 @@
// Package config loads and validates typed configuration files using viper and
// go-playground/validator.
//
// # Workflow
//
// Define a struct with mapstructure and validate tags, create a [Manager] with
// [NewManager], optionally configure hooks via [Manager.WithOpts], then call
// [Manager.Load] during startup. Use [Manager.C] or [Manager.Config] for quick
// access after load.
//
// # Environment overrides
//
// Set [ManagerOpts.EnvPrefix] or call [Manager.WithEnvOverride]. Nested keys use
// dots in YAML and underscores in env vars (for example MYAPP_DATABASE_USER).
//
// # Root directory discovery
//
// [RootDir] and [MustRootDir] locate a marker file by walking up from the working
// directory—useful when config lives near a repo root.
package config