loader

package
v0.0.0-...-3ac352a Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package loader provides implementations of the confii.Loader interface for various configuration sources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseContent

func ParseContent(data []byte, format formatparse.Format, source string) (map[string]any, error)

ParseContent parses raw bytes into a config map based on format. Exported for use by cloud loaders.

Types

type BasicAuth

type BasicAuth struct {
	Username string
	Password string
}

BasicAuth holds HTTP basic auth credentials.

type EnvFileLoader

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

EnvFileLoader loads configuration from a .env file. Format: KEY=VALUE per line with support for comments, quoting, and nested keys.

func NewEnvFile

func NewEnvFile(path string) *EnvFileLoader

NewEnvFile creates a new .env file loader. Defaults to ".env" if path is empty.

func (*EnvFileLoader) Load

func (l *EnvFileLoader) Load(_ context.Context) (map[string]any, error)

Load reads and parses the .env file at the configured path, returning key-value pairs as a configuration map.

func (*EnvFileLoader) Source

func (l *EnvFileLoader) Source() string

Source returns the identifier for this loader's configuration source.

type EnvLoaderOption

type EnvLoaderOption func(*EnvironmentLoader)

EnvLoaderOption configures the EnvironmentLoader.

func WithSeparator

func WithSeparator(sep string) EnvLoaderOption

WithSeparator sets the nesting separator (default "__").

type EnvironmentLoader

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

EnvironmentLoader loads configuration from environment variables matching a prefix. Variables are stripped of the prefix, split on the separator to create nested keys, and lowercased.

func NewEnvironment

func NewEnvironment(prefix string, opts ...EnvLoaderOption) *EnvironmentLoader

NewEnvironment creates a new environment variable loader. The prefix is uppercased automatically. The default separator is "__".

func (*EnvironmentLoader) Load

func (l *EnvironmentLoader) Load(_ context.Context) (map[string]any, error)

Load reads environment variables matching the configured prefix and parses them into a nested configuration map.

func (*EnvironmentLoader) Source

func (l *EnvironmentLoader) Source() string

Source returns the identifier for this loader's configuration source.

type HTTPLoader

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

HTTPLoader loads configuration from an HTTP/HTTPS endpoint.

func NewHTTP

func NewHTTP(url string, opts ...HTTPOption) *HTTPLoader

NewHTTP creates a new HTTP loader for the given URL.

func (*HTTPLoader) Load

func (l *HTTPLoader) Load(ctx context.Context) (map[string]any, error)

Load fetches configuration from the HTTP/HTTPS endpoint at the configured URL and parses the response body.

func (*HTTPLoader) Source

func (l *HTTPLoader) Source() string

Source returns the identifier for this loader's configuration source.

type HTTPOption

type HTTPOption func(*HTTPLoader)

HTTPOption configures the HTTPLoader.

func WithBasicAuth

func WithBasicAuth(username, password string) HTTPOption

WithBasicAuth sets HTTP basic auth credentials.

func WithHeaders

func WithHeaders(h map[string]string) HTTPOption

WithHeaders sets HTTP headers for the request.

func WithTimeout

func WithTimeout(d time.Duration) HTTPOption

WithTimeout sets the HTTP request timeout.

type INILoader

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

INILoader loads configuration from an INI file. Each section becomes a top-level key; keys within sections are nested.

func NewINI

func NewINI(path string) *INILoader

NewINI creates a new INI loader for the given file path.

func (*INILoader) Load

func (l *INILoader) Load(_ context.Context) (map[string]any, error)

Load reads and parses the INI file at the configured path, returning sections as nested configuration maps.

func (*INILoader) Source

func (l *INILoader) Source() string

Source returns the identifier for this loader's configuration source.

type JSONLoader

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

JSONLoader loads configuration from a JSON file.

func NewJSON

func NewJSON(path string) *JSONLoader

NewJSON creates a new JSON loader for the given file path.

func (*JSONLoader) Load

func (l *JSONLoader) Load(_ context.Context) (map[string]any, error)

Load reads and parses the JSON file at the configured path, returning the parsed configuration as a map.

func (*JSONLoader) Source

func (l *JSONLoader) Source() string

Source returns the identifier for this loader's configuration source.

type TOMLLoader

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

TOMLLoader loads configuration from a TOML file.

func NewTOML

func NewTOML(path string) *TOMLLoader

NewTOML creates a new TOML loader for the given file path.

func (*TOMLLoader) Load

func (l *TOMLLoader) Load(_ context.Context) (map[string]any, error)

Load reads and parses the TOML file at the configured path, returning the parsed configuration as a map.

func (*TOMLLoader) Source

func (l *TOMLLoader) Source() string

Source returns the identifier for this loader's configuration source.

type YAMLLoader

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

YAMLLoader loads configuration from a YAML file.

func NewYAML

func NewYAML(path string) *YAMLLoader

NewYAML creates a new YAML loader for the given file path.

func (*YAMLLoader) Load

func (l *YAMLLoader) Load(_ context.Context) (map[string]any, error)

Load reads and parses the YAML file at the configured path, returning the parsed configuration as a map.

func (*YAMLLoader) Source

func (l *YAMLLoader) Source() string

Source returns the identifier for this loader's configuration source.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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