command
Version:
v0.12.0
Opens a new window with list of versions in this module.
Published: May 20, 2026
License: Apache-2.0
Opens a new window with license information.
Imports: 6
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
Hooks example
Demonstrates all three hook points in one pipeline, showing the exact order they run.
What it shows
WithTransform: map stage, inspect and mutate the raw key-value map before binding
WithValidator: cross-field, validate relationships between fields (TLS cert + key consistency)
OnBound[T]: struct stage, post-binding normalization (lowercase the log level)
Pipeline order
Load sources -> WithTransform -> WithValidator -> WithBinding -> OnBound[T]
Run
cd examples/hooks && go run .
Tests
cd examples/hooks && go test -v
The tests cover:
- Happy path with all hooks running
WithTransform overriding log level for production
WithValidator rejecting TLS enabled without cert/key files
OnBound normalizing the log level to lowercase
Key ideas
- Hook points are ordered: transforms run before validators, which run before binding, which runs before
OnBound.
OnBound[T] is type-safe: passing a mismatched OnBound[Other] is a compile error, not a runtime panic.
WithValidator operates on the raw *Values map, making cross-field checks easy without Go struct reflection.
Documentation
¶
Package main demonstrates all three hook points in one pipeline.
Pipeline order:
- WithTransform — map stage: override log level for production.
- WithValidator — cross-field: TLS cert + key must both be set
when TLS is enabled.
- WithBinding — decode map into App struct.
- OnBound[App] — struct stage: normalize Logging.Level to lowercase.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.