hotconfig

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2022 License: MIT Imports: 7 Imported by: 0

README

go-hotconfig

A configuration parser designed with hot-reloads (i.e. reloading during runtime) in mind. Supports customizable parsing from CLI args, environment vars and configuration file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// FlagsCLI allows specifying extra CLI flags ontop of those
	// generated from your values type. These will be returned to
	// you with raw string values from .ParseCLI(). An example use
	// case here is setting config file location, usage printing, etc.
	CLI cli.FlagSet

	// FlagsEnv allows specifying extra env flags ontop of those
	// generated from your values type. These will be returned to
	// you with raw string value from .ParseEnv(). An example use
	// case here is setting config file location.
	Env env.FlagSet

	// DecodeFile allows specifying a custom file decoder, where 'dst' interface{}
	// is your configuration values object and src is the file opened from path
	// passed to ConfigState.ReadFile().
	//
	// If nil the default of env.FileDecoder(...) will be used.
	DecodeFile func(dst interface{}, src *os.File) error
}

type ConfigState

type ConfigState[Values any] struct {
	// contains filtered or unexported fields
}

func New

func New[Values any](cfg Config) *ConfigState[Values]

func (*ConfigState[Values]) CLI

func (st *ConfigState[Values]) CLI() *cli.FlagSet

CLI provides access to the ConfigState's underlying cli.FlagSet. NOT CONCURRENCY SAFE.

func (*ConfigState[Values]) Config

func (st *ConfigState[Values]) Config(fn func(*Values))

Config provides safe access to ConfigState's config values.

func (*ConfigState[Values]) Env

func (st *ConfigState[Values]) Env() *env.FlagSet

Env provides access to the ConfigState's underlying env.FlagSet. NOT CONCURRENCY SAFE.

func (*ConfigState[Values]) ParseCLI

func (st *ConfigState[Values]) ParseCLI(args []string) (unknown []string, err error)

ParseCLI will parse CLI arguments and safely load them into the ConfigState's config values, returning unrecognized arguments.

func (*ConfigState[Values]) ParseCLIStrict

func (st *ConfigState[Values]) ParseCLIStrict(args []string) error

ParseCLIStrict will perform .ParseCLI() but return error in the case that unknown arguments are returned.

func (*ConfigState[Values]) ParseEnv

func (st *ConfigState[Values]) ParseEnv(env []string) error

ParseEnv will parse environment variables and safely load them into the ConfigState's config values.

func (*ConfigState[Values]) ReadFile

func (st *ConfigState[Values]) ReadFile(path string) error

ReadFile will parse file at given path and safely load variables into ConfigState's config values.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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