Documentation
¶
Index ¶
- Constants
- Variables
- type CustomValidatorFunc
- type FieldError
- type LoadReport
- type Option
- func FromDotEnvFile(path string) Option
- func FromEnv() Option
- func FromJSONBytes(data []byte) Option
- func FromJSONFile(path string) Option
- func FromTOMLBytes(data []byte) Option
- func FromTOMLFile(path string) Option
- func FromYAMLBytes(data []byte) Option
- func FromYAMLFile(path string) Option
- func Strict() Option
- func WithCustomValidator(name string, fn CustomValidatorFunc) Option
- func WithEnvPrefix(prefix string) Option
- func WithUnknownKeySuggestionMode(mode UnknownKeySuggestionMode) Option
- type ReportEntry
- type UnknownKeySuggestionMode
- type ValidationError
Constants ¶
const Version = "v0.4.0"
Version is the current module version. It is updated by the release workflow from the release tag.
Variables ¶
var ( // ErrInvalidTarget indicates target passed to Load is invalid. ErrInvalidTarget = errs.InvalidTarget // ErrInvalidSchema indicates schema configuration or tags are invalid. ErrInvalidSchema = errs.InvalidSchema // ErrDecode indicates source decode or type conversion failure. ErrDecode = errs.Decode // ErrValidation indicates one or more validation rules failed. ErrValidation = errs.Validation )
Functions ¶
This section is empty.
Types ¶
type CustomValidatorFunc ¶ added in v0.4.0
CustomValidatorFunc validates a field value using the optional rule value from the validate tag (for example: validate:"myrule=arg").
Return nil when valid, or a non-nil error to report a validation failure.
type FieldError ¶
FieldError represents an error for a specific configuration field path.
func (FieldError) Error ¶
func (e FieldError) Error() string
type LoadReport ¶ added in v0.3.1
type LoadReport struct {
Entries []ReportEntry
}
LoadReport describes resolved values and their sources after loading.
func Load ¶
func Load(target any, opts ...Option) (*LoadReport, error)
Load builds a schema from target and applies defaults, configured sources, and validations in order.
target must be a non-nil pointer to a struct.
func (*LoadReport) Print ¶ added in v0.3.1
func (r *LoadReport) Print(w io.Writer)
Print writes a tabular report to w.
type Option ¶
type Option func(*loadOptions) error
Option configures Load behavior.
func FromDotEnvFile ¶ added in v0.4.0
FromDotEnvFile loads values from a .env file using field env tags.
func FromEnv ¶
func FromEnv() Option
FromEnv loads values from process environment variables using field env tags.
func FromJSONBytes ¶ added in v0.4.0
FromJSONBytes loads values from JSON bytes.
func FromJSONFile ¶
FromJSONFile loads values from a JSON file.
func FromTOMLBytes ¶ added in v0.4.0
FromTOMLBytes loads values from TOML bytes.
func FromTOMLFile ¶ added in v0.2.0
FromTOMLFile loads values from a TOML file.
func FromYAMLBytes ¶ added in v0.4.0
FromYAMLBytes loads values from YAML bytes.
func FromYAMLFile ¶
FromYAMLFile loads values from a YAML file.
func Strict ¶ added in v0.3.1
func Strict() Option
Strict enables strict schema loading and mapping checks.
func WithCustomValidator ¶ added in v0.4.0
func WithCustomValidator(name string, fn CustomValidatorFunc) Option
WithCustomValidator registers a custom validator by rule name. The rule can then be used in validate tags (for example: validate:"myrule=arg").
func WithEnvPrefix ¶ added in v0.4.0
WithEnvPrefix prepends prefix to all env-tag lookups for env and .env sources.
func WithUnknownKeySuggestionMode ¶ added in v0.3.0
func WithUnknownKeySuggestionMode(mode UnknownKeySuggestionMode) Option
WithUnknownKeySuggestionMode sets handling mode for unknown structured keys.
type ReportEntry ¶ added in v0.3.1
ReportEntry is a single resolved field in a LoadReport.
type UnknownKeySuggestionMode ¶ added in v0.3.0
type UnknownKeySuggestionMode = common.UnknownKeySuggestionMode
UnknownKeySuggestionMode controls how unknown structured keys are handled.
const ( // ModeWarn prints a warning for unknown keys and continues. ModeWarn UnknownKeySuggestionMode = common.UnknownKeySuggestionWarn // ModeError returns a decode error for unknown keys. ModeError UnknownKeySuggestionMode = common.UnknownKeySuggestionError // ModeOff ignores unknown keys. ModeOff UnknownKeySuggestionMode = common.UnknownKeySuggestionOff )
type ValidationError ¶
type ValidationError struct {
Fields []FieldError
}
ValidationError contains all field-level validation failures.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
func (*ValidationError) Unwrap ¶
func (e *ValidationError) Unwrap() error