loader

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package file provides config loader support for xconfig

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPlugin

func NewPlugin(path string, unmarshal Unmarshal, config Config, loader *Loader) plugins.Plugin

NewPlugin returns a new file loader plugin for the given path and unmarshal function.

func NewReader

func NewReader(src io.Reader, unmarshal Unmarshal) plugins.Plugin

NewReader returns a xconfig plugin that unmarshals the content of the provided io.Reader into the config using the provided unmarshal function. The src will be closed if it is an io.Closer.

Types

type Config

type Config struct {
	// indicates if a file that does not exist should be ignored.
	Optional bool
	// indicates if unknown fields should cause an error.
	DisallowUnknownFields bool
}

Config describes the options required for a file.

type File

type File struct {
	Path      string
	Unmarshal Unmarshal
	Optional  bool
}

type Loader

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

Loader represents a set of file paths and the appropriate unmarshal function for the given file.

func NewLoader

func NewLoader(decoders map[string]Unmarshal) (*Loader, error)

func (*Loader) AddFile

func (f *Loader) AddFile(path string, optional bool) error

AddFile appends a new file to the list of files.

func (*Loader) AddFiles

func (f *Loader) AddFiles(paths []string, optional bool) error

AddFiles appends multiple files to the list of files.

func (*Loader) ClearUnknownFields

func (f *Loader) ClearUnknownFields()

ClearUnknownFields clears the list of unknown fields.

func (*Loader) DisallowUnknownFields

func (f *Loader) DisallowUnknownFields(disallow bool)

DisallowUnknownFields enables strict validation of configuration files. When enabled, loading will fail if any unknown fields are found.

func (*Loader) GetUnknownFields

func (f *Loader) GetUnknownFields() map[string][]string

GetUnknownFields returns all unknown fields found in configuration files. Returns a map where keys are file paths and values are slices of unknown field paths.

func (*Loader) Plugins

func (f *Loader) Plugins() []plugins.Plugin

Plugins constructs a slice of Plugin from the Files list of paths and unmarshal functions.

func (*Loader) PresentFields added in v0.2.6

func (f *Loader) PresentFields() map[string]struct{}

PresentFields returns a union set of all leaf field paths that were explicitly present in loaded configuration files.

func (*Loader) RegisterDecoder

func (f *Loader) RegisterDecoder(format string, decoder Unmarshal) error

RegisterDecoder registers a new decoder for the given format.

type UnknownField

type UnknownField struct {
	Path string // Field path (e.g., "Database.Extra.Field")
	File string // Source file path
}

UnknownField represents a single unknown field with its path and source file.

type UnknownFieldsError

type UnknownFieldsError struct {
	// Fields contains a map of file paths to their unknown fields
	Fields map[string][]string
}

UnknownFieldsError represents an error when unknown fields are found in configuration files.

func (*UnknownFieldsError) Error

func (e *UnknownFieldsError) Error() string

Error implements the error interface.

type Unmarshal

type Unmarshal func(src []byte, v any) error

Unmarshal is any function that maps the source bytes to the provided config.

Jump to

Keyboard shortcuts

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