loader

package
v0.9.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = []interface{}{
	ucfg.PathSep("."),
	ucfg.ResolveEnv,
	ucfg.VarExp,
	VarSkipKeys("inputs"),
}

DefaultOptions defaults options used to read the configuration

View Source
var ErrNoConfiguration = errors.New("no configuration found")

ErrNoConfiguration is returned when no configuration are found.

Functions

func DiscoverFiles

func DiscoverFiles(patterns ...string) ([]string, error)

DiscoverFiles takes a slices of wildcards patterns and try to discover all the matching files recursively and will stop on any errors.

Types

type Config

type Config ucfg.Config

Config custom type over a ucfg.Config to add new methods on the object.

func LoadFile

func LoadFile(path string) (*Config, error)

LoadFile take a path and load the file and return a new configuration.

func LoadFiles

func LoadFiles(paths ...string) (*Config, error)

LoadFiles takes multiples files, load and merge all of them in a single one.

func MustNewConfigFrom

func MustNewConfigFrom(from interface{}) *Config

MustNewConfigFrom try to create a configuration based on the type passed as arguments and panic on failures.

func New

func New() *Config

New creates a new empty config.

func NewConfigFrom

func NewConfigFrom(from interface{}, opts ...interface{}) (*Config, error)

NewConfigFrom takes a interface and read the configuration like it was YAML.

func (*Config) Enabled

func (c *Config) Enabled() bool

Enabled return the configured enabled value or true by default.

func (*Config) Merge

func (c *Config) Merge(from interface{}, opts ...interface{}) error

Merge merges two configuration together.

func (*Config) ToMapStr

func (c *Config) ToMapStr() (map[string]interface{}, error)

ToMapStr takes the config and transform it into a map[string]interface{}

func (*Config) Unpack

func (c *Config) Unpack(to interface{}, opts ...interface{}) error

Unpack unpacks a struct to Config.

type DiscoverFunc

type DiscoverFunc func() ([]string, error)

DiscoverFunc is a function that discovers a list of files to load.

func Discoverer

func Discoverer(patterns ...string) DiscoverFunc

Discoverer returns a DiscoverFunc that discovers all files that match the given patterns.

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

Loader is used to load configuration from the paths including appending multiple input configurations.

func NewLoader

func NewLoader(logger *logp.Logger, inputsFolder string) *Loader

NewLoader creates a new Loader instance to load configuration files from different paths.

func (*Loader) Load

func (l *Loader) Load(files []string) (*Config, error)

Load iterates over the list of files and loads the confguration from them. If a configuration file is under the folder set in `agent.config.inputs.path` it is appended to a list. If it is a regular config file, it is merged into the result config. The list of input configurations is merged into the result last.

type Option

type Option func(*options)

Option is an option type that modifies how loading configs work

func VarSkipKeys

func VarSkipKeys(keys ...string) Option

VarSkipKeys prevents variable expansion for these keys.

The provided keys only skip if the keys are top-level keys.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL