Documentation ¶
Overview ¶
Package config provides helpers for handling config structs
Index ¶
- func AsValidationErrors(err error) (validator.ValidationErrors, bool)
- func CanUpdate(v any) bool
- func Join(directories []string, base string, extensions []string) ([]string, error)
- func NewPathError(filename, op string, err error) *os.PathError
- func Prepare(v any) error
- func Set(v any) error
- func SetDefaults(v any) error
- func Validate(v any) error
- type Decoder
- type DecoderFunc
- type Loader
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsValidationErrors ¶
AsValidationErrors gives access to a slice of validator.FieldError
func Join ¶ added in v0.3.0
Join combines a list of directories with a name and an optional list of extensions. This are `/` separated, absolute, but without the initial `/`. Following fs.ValidPath rules. Final result is cleaned.
func NewPathError ¶ added in v0.3.0
NewPathError is a shortcut to generate os.PathError.
func Set ¶
Set applies `default` struct-tags and SetDefaults() recursively. If the given object has a `SetDefaults() error` method, it will be ignored. Any `SetDefaults() error` deeper in the struct will be called.
func SetDefaults ¶
SetDefaults applies `default` struct-tags and SetDefaults() recursively. If the given object has a `SetDefaults() error` method, it will be invoked instead.
Types ¶
type Decoder ¶ added in v0.3.0
A Decoder attempts to convert the contents of a file into a [T] type.
type DecoderFunc ¶ added in v0.3.0
A DecoderFunc represents a function that can act as a full Decoder.
type Loader ¶ added in v0.3.0
type Loader[T any] struct { // NewDecoder returns a [Decoder] based on the filename NewDecoder func(string) (Decoder[T], error) // IsSkip checks if the error returned by the [Decoder] // indicates we should try the next option instead of // failing. [os.IsNotExist] is always tested first. IsSkip func(error) bool // Options are applied to objects after decoding and // before Load() returns. Options []Option[T] // contains filtered or unexported fields }
Loader tries to load an object from the first success on a list of options.
func (*Loader[T]) Last ¶ added in v0.3.0
Last returns the filename last used. empty if it was the Fallback.
func (*Loader[T]) NewFromFile ¶ added in v0.3.0
NewFromFile returns the first successfully decoded option.
func (*Loader[T]) NewFromFileOS ¶ added in v0.3.0
NewFromFileOS returns the first successfully decoded option.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package appdir provides helpers to compose filenames to be used by applications.
|
Package appdir provides helpers to compose filenames to be used by applications. |
Package expand implements helpers to expand shell-style variables within config files before they are parsed
|
Package expand implements helpers to expand shell-style variables within config files before they are parsed |