config

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load[T any](conf *Config) (T, error)

Load reads configuration, using it to populate a struct. See Options for information on the supported configuration sources.

The struct should contains fields with "koanf" tags identifying the configuration value to assign. For example:

type LoggingConfig struct {
	Level string `koanf:"logging.level"`
}

The "koanf" struct tag value must use "." delimited keys for nested values. The field type can be anything supported by mapstructure, or an implementation of encoding.TextUnmarshaler.

A default value can be set using a "default" struct tag with the desired value. For example:

type LoggingConfig struct {
	Level string `koanf:"logging.level" default:"info"`
}

A field type can be anything supported by defaults, or an implementation of defaults.Setter, encoding.TextUnmarshaler, or encoding/json.Unmarshaler.

Types

type Config

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

Config provides loading of configuration values for a service.

func New

func New(opts *Options) *Config

New creates a new Config instance.

type Options

type Options struct {
	// The prefix of environment variables to read configuration from. Matching environment
	// variables have the prefix removed, are converted to lowercase and any underscores are
	// replaced with ".". For example, "APP_LOG_LEVEL" with a prefix of "APP_" would become
	// "log.level".
	EnvPrefix string

	// The file paths to read configuration from. Supported file formats and extensions are:
	//
	// - JSON: .json
	// - YAML: .yml, .yaml
	// - TOML: .toml
	//
	// The file content is read into a map where nested map keys are joined using ".". For example,
	// a JSON file containing {"log":{"level":"info"}} would become "log.level".
	Files []string

	// The directories of Kubernetes pod mounts to read configuration from. The filenames of the
	// mounted values become the configuration keys. For example, a configmap field of "log.level"
	// can be accessed at the same name.
	Mounts []string
}

Options provides the values to bootstrap configuration collection.

Directories

Path Synopsis
providers

Jump to

Keyboard shortcuts

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