Documentation
¶
Overview ¶
Package config provides functions and types to define config objects and load and save them to TOML files.
Index ¶
- func Defaults[C any](cfg *C, defaultsData []byte) (*C, error)
- func Load[C any](cfg *C, path string, defaultsData []byte, strict bool) (*C, error)
- func MarshalEnum[E comparable](e E, marshalMap map[E]string) ([]byte, error)
- func MarshalStringerEnum[E fmt.Stringer](e E) ([]byte, error)
- func Save(cfg any, path string, perm os.FileMode) error
- func UnmarshalEnum[E comparable](unmarshalMap map[string]E, text []byte) (E, error)
- type DurationSpec
- type NetworkSpec
- type NetworkSpecs
- type RegexpSpec
- type TimeLocationSpec
- type URLSpec
- type URLSpecs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Defaults ¶
Defaults creates a default config from the given default config data (usually statically embedded).
func Load ¶
Load loads a config from a file. Before loading the config from the given path, the config object is initialized using the given default data.
If the strict flag is set non-matching fields will cause errors. Otherwise they are silently ignored.
func MarshalEnum ¶
func MarshalEnum[E comparable](e E, marshalMap map[E]string) ([]byte, error)
MarshalEnum is a helper function to implement encoding.TextMarshaler for an enum type based on the given map.
func MarshalStringerEnum ¶ added in v0.0.2
MarshalStringerEnum is a helper function to implement encoding.TextMarshaler for an enum type based on the enum type's fmt.Stringer interface.
func UnmarshalEnum ¶
func UnmarshalEnum[E comparable](unmarshalMap map[string]E, text []byte) (E, error)
UnmarshalEnum is a helper function to implement encoding.TextUnmarshaler for an enum type.
Types ¶
type DurationSpec ¶
DurationSpec supports Marshaling of time.Duration values.
func (*DurationSpec) MarshalText ¶
func (spec *DurationSpec) MarshalText() ([]byte, error)
func (*DurationSpec) UnmarshalText ¶
func (spec *DurationSpec) UnmarshalText(text []byte) error
type NetworkSpec ¶
NetworkSpec supports Marshaling of netip.Prefix values.
func (*NetworkSpec) MarshalText ¶
func (spec *NetworkSpec) MarshalText() ([]byte, error)
func (*NetworkSpec) UnmarshalText ¶
func (spec *NetworkSpec) UnmarshalText(text []byte) error
type NetworkSpecs ¶
type NetworkSpecs []NetworkSpec
NetworkSpecs defines an array of [NetworkSpec]s.
func (NetworkSpecs) Prefixes ¶
func (specs NetworkSpecs) Prefixes() []netip.Prefix
Prefixes returns the [netip.Prefix]es contained in this array.
type RegexpSpec ¶
RegexpSpec supports Marshaling of regexp.Regexp values.
func (*RegexpSpec) MarshalText ¶
func (spec *RegexpSpec) MarshalText() ([]byte, error)
func (*RegexpSpec) UnmarshalText ¶
func (spec *RegexpSpec) UnmarshalText(text []byte) error
type TimeLocationSpec ¶
TimeLocationSpec supports Marshaling of time.Location values.
func (*TimeLocationSpec) MarshalText ¶
func (spec *TimeLocationSpec) MarshalText() ([]byte, error)
func (*TimeLocationSpec) UnmarshalText ¶
func (spec *TimeLocationSpec) UnmarshalText(text []byte) error
type URLSpec ¶
URLSpec supports Marshaling of url.URL values.