cfg

package
Version: v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2020 License: Apache-2.0 Imports: 11 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotPointer = errors.New("dst is not a pointer")
)

Functions

func Parse

func Parse(dst Cloneable) error

Parse is a higher level wrapper for Unmarshal that automatically parses flags and a .yaml file

func Unmarshal

func Unmarshal(dst Cloneable, sources ...Source) error

Unmarshal merges the values of the various configuration sources and sets them on `dst`. The object must be compatible with `json.Unmarshal`.

Types

type Cloneable added in v1.6.0

type Cloneable interface {
	Clone() flagext.Registerer
}

Cloneable is a config which can be cloned into a flagext.Registerer Contract: the cloned value must not mutate the original.

type Source

type Source func(Cloneable) error

Source is a generic configuration source. This function may do whatever is required to obtain the configuration. It is passed a pointer to the destination, which will be something compatible to `json.Unmarshal`. The obtained configuration may be written to this object, it may also contain data from previous sources.

func Flags

func Flags() Source

Flags parses the flag from the command line, setting only user-supplied values on the flagext.Registerer passed to Defaults()

func JSON

func JSON(f *string) Source

JSON returns a Source that opens the supplied `.json` file and loads it.

func YAML

func YAML(f string) Source

YAML returns a Source that opens the supplied `.yaml` file and loads it.

func YAMLFlag

func YAMLFlag(args []string, name string) Source

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL