file

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2025 License: MIT Imports: 5 Imported by: 5

Documentation

Overview

Package file provides config file support for uconfig

Index

Constants

This section is empty.

Variables

View Source
var ErrEncodingFailed = errors.New("failed to decode file")
View Source
var ErrFileExtNotSupported = errors.New("file extension not supported")

Functions

func New

func New(path string, unmarshal Unmarshal, config Config) plugins.Plugin

New returns an EnvSet.

func NewMulti added in v0.8.0

func NewMulti(path string, unmarshalOptions UnmarshalOptions, optional bool) plugins.Plugin

NewMutli returns a multi unmarshal plugin that can decode the file from path using various Unmarshal functions provided in unmarshal map. This is usually used as a second stage to load configurations based on a flag or configuration value.

func NewReader

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

NewReader returns a uconfig 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
}

Config describes the options required for a file.

type Files

type Files []struct {
	Path      string
	Unmarshal Unmarshal
	Optional  bool
}

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

func (Files) Plugins

func (f Files) Plugins() []plugins.Plugin

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

type Plugin added in v0.8.0

type Plugin interface {
	plugins.Plugin
	FilePath() string
}

type Unmarshal

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

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

type UnmarshalOptions added in v0.8.0

type UnmarshalOptions map[string]Unmarshal

Jump to

Keyboard shortcuts

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