config

package module
v0.0.0-...-ebfe679 Latest Latest
Warning

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

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

README

go-config

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSourcerNil         = errors.New("source cannot be nil")
	ErrNotPointer         = errors.New("input must be a pointer")
	ErrNotStruct          = errors.New("input must be a struct")
	ErrPrivateField       = errors.New("cannot parse private fields")
	ErrUnknownOption      = errors.New("unknown option")
	ErrMissingKey         = errors.New("missing key")
	ErrRequiredAndDefault = errors.New("cannot set both `required` and `default`")
	ErrMissingRequired    = errors.New("missing required value")
	ErrInvalidMapItem     = errors.New("invalid map item")
	ErrPrefixNotStruct    = errors.New("prefix is only valid on struct types")
)

Functions

func ProcessWith

func ProcessWith(ctx context.Context, target interface{}, s Sourcer, mfn ...MutatorFunc) error

Types

type Decoder

type Decoder interface {
	Decode(val string) error
}

Decoder is an interface that custom types/fields can implement to control how decoding takes place. For example:

type MyType string

func (mt MyType) Decode(val string) error {
    return "CUSTOM-"+val
}

type FieldOptions

type FieldOptions struct {
	Default  string
	Required bool
	Prefix   string
}

FieldOptions maintain flag options for a given field.

type MutatorFunc

type MutatorFunc func(ctx context.Context, k, v string) (string, error)

MutatorFunc is a function that mutates a given value before it is passed along for processing. This is useful if you want to mutate the environment variable value before it's converted to the proper type.

type Sourcer

type Sourcer interface {
	// Source takes given key and returns the corresponding string value.
	// Returns true if found with the value. If a value is
	// not found, it returns the empty string and false.
	Source(key string) (string, bool)
}

Sourcer is an interface that provides a lookup for a string-based key.

func NewEnvSourcer

func NewEnvSourcer() Sourcer

func PrefixSourcer

func PrefixSourcer(prefix string, s Sourcer) Sourcer

PrefixSourcer looks up environment configuration using the specified prefix. This is useful if you want all your variables to start with a particular prefix like "MY_APP_".

Jump to

Keyboard shortcuts

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