file

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 5 Imported by: 6

Documentation

Overview

Package file provides config file support for uconfig

Index

Constants

This section is empty.

Variables

View Source
var ErrFileExtNotSupported = errors.New("file extension not supported")

Functions

func FileNames added in v0.13.0

func FileNames(ps []plugins.Plugin) []string

FileNames returns the display names of file paths from a list of plugins, filtering out non-file plugins. These are the names as provided by the user, not resolved absolute paths.

func FilePaths added in v0.12.0

func FilePaths(ps []plugins.Plugin) []string

FilePaths returns the resolved filesystem paths from a list of plugins, filtering out non-file plugins. Paths are available after Walk has been called.

func New

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

New returns a file plugin.

func NewMulti added in v0.8.0

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

NewMulti 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      Path
	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 Path added in v0.13.0

type Path struct {
	Name    string
	Resolve func() string
}

Path pairs a display name with a lazy path resolver. The Name is shown in usage output; Resolve is called during Walk to obtain the actual filesystem path.

func Absolute added in v0.13.0

func Absolute(path string) Path

Absolute returns a Path for a fixed absolute path.

func Relative added in v0.13.0

func Relative(path string) Path

Relative returns a Path that resolves a relative path against the working directory at the time of the call.

func Workspace added in v0.13.0

func Workspace(name string) Path

Workspace returns a Path that walks up the directory tree looking for a file at the given relative path (e.g. ".myapp/config"). Returns the absolute path of the first match, or empty string if not found.

The search always starts from the current working directory.

This implements the common ancestor-directory search pattern used by tools like git (.git), eslint (.eslintrc), and similar.

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