Documentation
¶
Overview ¶
Package cs is the main package for the cs library
Index ¶
- Constants
- func AddDefaultSource(src Source)
- func AddLateBindingSource(src LateBindingSource)
- func AddSource(src Source)
- func Get[T any](c Config, key string) (*T, error)
- func MustGet[T any](c Config, key string) *T
- func MustRead(key string, into any)
- func Read(key string, into any) error
- type Config
- type DumpOption
- type Entry
- type Error
- type LateBindingSource
- type Source
- type Validating
Constants ¶
const ( // DescriptionKey is a reserved key for a map source to provide a metadata description DescriptionKey = "_description" // DescriptionTagName name of the description tag DescriptionTagName = "description" )
Variables ¶
This section is empty.
Functions ¶
func AddDefaultSource ¶ added in v0.0.7
func AddDefaultSource(src Source)
AddDefaultSource adds a source of default configuration values to the global configuration instance.
func AddLateBindingSource ¶
func AddLateBindingSource(src LateBindingSource)
AddLateBindingSource adds a source which is consulted at read time, meaning each property present on the underlying results are looked up again with provided keys
func AddSource ¶
func AddSource(src Source)
AddSource adds a source to build the root cs object. Sources are invoked in the order they are added. Sources added later take precedent over sources added earlier
func Get ¶ added in v0.0.2
Get retrieves the value of type T associated with the specified key from the provided Config. Returns an error if retrieval fails.
Types ¶
type Config ¶
type Config interface {
// AddDefaultSource adds a source that provides default configuration values, used as a fallback if no other source provides a value.
AddDefaultSource(src Source)
// AddSource adds a source to build the root cs object. Sources are invoked in the order they are added.
// Sources added later take precedent over sources added earlier
AddSource(src Source)
// AddLateBindingSource adds a source which is consulted at read time, meaning each property present on the
// underlying results are looked up again with provided keys
AddLateBindingSource(src LateBindingSource)
// Read reads value from the key and assigns it to the provided object, which must be a pointer to a supported value
// supported values are all primitives and a map
Read(key string, into any) error
// MustRead reads and panics on error
MustRead(key string, into any)
// SetValidatingHook sets a custom hook for validation. By default the struct is checked to implement Validating and
// if so the method is invoked
SetValidatingHook(func(in any) error)
// Dump dumps out the config and metadata
// Default dumps to stdout with descriptions and values
Dump(opts ...DumpOption) error
}
Config is main interface for cs data. Keys are in dot format, `prefix.name`
type DumpOption ¶ added in v0.2.0
type DumpOption func(o *dumpOptions)
DumpOption represents a functional option used to configure the behavior of the dump operation.
func WithDumpOut ¶ added in v0.2.0
func WithDumpOut(out io.Writer) DumpOption
WithDumpOut sets a custom io.Writer as the output destination for the dump process.
func WithOmitEmpty ¶ added in v0.2.0
func WithOmitEmpty() DumpOption
WithOmitEmpty instructs ths dumper to not show empty entries
type Entry ¶ added in v0.2.0
type Entry struct {
}
Entry allows for a description to be applied via a tag to this struct
type Error ¶ added in v0.0.5
type Error struct {
// Key specifies the config key requested which produced the error
Key string
// TypeName indicates the type associated with the error.
TypeName string
// Detail contains the underlying error providing further information.
Detail error
}
Error represents a structure for detailed error handling with config key metadata.
type LateBindingSource ¶
LateBindingSource source returns a cs value for a given key at the time a csuration is read
type Validating ¶ added in v0.0.3
type Validating interface {
Validate() error
}
Validating marks a struct with the ability to validate itself after being unmarshalled
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package sources contains various cs sources
|
Package sources contains various cs sources |
|
json
Package json supports cs sources from json files
|
Package json supports cs sources from json files |
|
yaml
Package yaml support cs sources from yaml files
|
Package yaml support cs sources from yaml files |