config

package
v0.0.0-...-0253919 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

README

config

import go.pitz.tech/lib/config

Usage

var (
	// ErrFileDoesNotExist is returned when the file we're interacting with does not exist.
	ErrFileDoesNotExist = errors.New("file does not exist")

	// ErrFileMissingExtension is returned when the provided file is missing an extension.
	ErrFileMissingExtension = errors.New("file missing extension")

	// ErrUnsupportedFileExtension is returned when we don't recognize a given file extension.
	ErrUnsupportedFileExtension = errors.New("unsupported file extension")
)
var DefaultLoader = Loader{
	".json": encoding.JSON,
	".toml": encoding.TOML,
	".yaml": encoding.YAML,
	".yml":  encoding.YAML,
	".xml":  encoding.XML,
}

DefaultLoader provides a default Loader implementation that supports reading a variety of files.

func Load
func Load(ctx context.Context, v interface{}, filePaths ...string) error

Load provides a convenience function for being able to load configuration using the DefaultLoader.

type Loader
type Loader map[string]*encoding.Encoding

Loader provides functionality for reading a variety of file formats into a struct.

func (Loader) Load
func (l Loader) Load(ctx context.Context, v interface{}, filePaths ...string) error

Load reads the provided files (if they exist) and unmarshals the data into the provided interface.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFileDoesNotExist is returned when the file we're interacting with does not exist.
	ErrFileDoesNotExist = errors.New("file does not exist")

	// ErrFileMissingExtension is returned when the provided file is missing an extension.
	ErrFileMissingExtension = errors.New("file missing extension")

	// ErrUnsupportedFileExtension is returned when we don't recognize a given file extension.
	ErrUnsupportedFileExtension = errors.New("unsupported file extension")
)
View Source
var DefaultLoader = Loader{
	".json": encoding.JSON,
	".toml": encoding.TOML,
	".yaml": encoding.YAML,
	".yml":  encoding.YAML,
	".xml":  encoding.XML,
}

DefaultLoader provides a default Loader implementation that supports reading a variety of files.

Functions

func Load

func Load(ctx context.Context, v interface{}, filePaths ...string) error

Load provides a convenience function for being able to load configuration using the DefaultLoader.

Types

type Loader

type Loader map[string]*encoding.Encoding

Loader provides functionality for reading a variety of file formats into a struct.

func (Loader) Load

func (l Loader) Load(ctx context.Context, v interface{}, filePaths ...string) error

Load reads the provided files (if they exist) and unmarshals the data into the provided interface.

Jump to

Keyboard shortcuts

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