sourcefile

package
v0.4.18 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package sourcefile loads configuration from YAML, JSON, or TOML files.

Format is auto-detected from extension (.yaml, .json, .toml).

Example:

source := sourcefile.New("config.yaml", sourcefile.Options{Required: true})
loader := rigging.NewLoader[Config]().WithSource(source)

Subtree example:

source := sourcefile.New("config.yaml", sourcefile.Options{
	Root: "root.section",
})
loader := rigging.NewLoader[Config]().WithSource(source)

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRootNotFound is returned when Options.Root does not exist in the parsed file.
	ErrRootNotFound = errors.New("sourcefile: root not found")
	// ErrRootNotMap is returned when Options.Root resolves to a non-map value.
	ErrRootNotMap = errors.New("sourcefile: root is not a map")
	// ErrInvalidRoot is returned when Options.Root has invalid dot-path syntax.
	ErrInvalidRoot = errors.New("sourcefile: invalid root path")
)

Functions

func New

func New(path string, opts Options) rigging.Source

New creates a file-based configuration source.

Types

type Options

type Options struct {
	// Format: "yaml", "json", or "toml". Auto-detected from extension if empty.
	Format string

	// Required: if true, missing files cause an error. Default: false (returns empty map).
	Required bool

	// Root selects a dot-separated map path inside the parsed file (for example, "root.section").
	// When set, only that subtree is flattened and exposed as the source root.
	Root string
}

Options configures file source behavior.

Jump to

Keyboard shortcuts

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