pantry

package module
v0.0.0-...-6ced1e9 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2018 License: MIT Imports: 20 Imported by: 0

README

pantry

Golang config library.

Documentation

Index

Constants

View Source
const (
	LocationConfigDir      = "${configdir}"
	LocationApplicationDir = "${appdir}"
	LocationCurrentDir     = "${curdir}"
	LocationHomeDir        = "${home}"
)

Variables

View Source
var Formats = ConfigFormats{}

Formats contains marshalers and unmarshalers for different file formats

Functions

func AutoReload

func AutoReload() func(*LoadOptions)

func IsUnfoundLocation

func IsUnfoundLocation(err error) bool

func Watch

func Watch(w Watcher) func(*LoadOptions)

func WatchContext

func WatchContext(w Watcher, ctx context.Context) func(*LoadOptions)

Types

type BaseBox

type BaseBox struct {
	// contains filtered or unexported fields
}

func (*BaseBox) Path

func (bb *BaseBox) Path() string

type Box

type Box interface {
	Path() string
	Get() ([]byte, error)
	Set(data []byte) error
	Watch(task func(err error)) error
	WatchContext(ctx context.Context, task func(err error)) error
}

Box

type ConfigEncodeError

type ConfigEncodeError struct {
	// contains filtered or unexported fields
}

ConfigEncodeError denotes failing to encode configuration

func (ConfigEncodeError) Error

func (e ConfigEncodeError) Error() string

Returns the formatted configuration error.

type ConfigFormat

type ConfigFormat struct {
	Marshal   MarshalFunc
	Unmarshal UnmarshalFunc
}

type ConfigFormats

type ConfigFormats map[string]*ConfigFormat

func (ConfigFormats) Register

func (c ConfigFormats) Register(format string, m MarshalFunc, um UnmarshalFunc)

Register format marshaler and unmarphaler

func (ConfigFormats) Search

func (c ConfigFormats) Search(format string) (*ConfigFormat, error)

type ConfigParseError

type ConfigParseError struct {
	// contains filtered or unexported fields
}

ConfigParseError denotes failing to parse configuration file.

func (ConfigParseError) Error

func (e ConfigParseError) Error() string

Returns the formatted configuration error.

type Enviropment

type Enviropment struct {
	Use            bool
	Prefix         string
	Hierarchically bool
}

func (*Enviropment) Get

func (e *Enviropment) Get(v reflect.Value, name string) (err error)

type FileBox

type FileBox struct {
	BaseBox
}

FileBox

func NewFileBox

func NewFileBox(path string) *FileBox

func (*FileBox) Get

func (fb *FileBox) Get() ([]byte, error)

func (*FileBox) Set

func (fb *FileBox) Set(data []byte) error

func (*FileBox) Watch

func (fb *FileBox) Watch(task func(err error)) error

func (*FileBox) WatchContext

func (fb *FileBox) WatchContext(ctx context.Context, task func(err error)) error

type Flag

type Flag struct {
	Name     string // name as it appears on command line
	Short    string // optional short name
	Usage    string // help message
	DefValue string // default value (as text); for usage message
	//Type     reflect.Type
	Value reflect.Value
}

type Flags

type Flags struct {
	Using          FlagsUsing
	FlagSet        *flag.FlagSet
	Args           []string
	ConfigPathFlag string
	Hierarchically bool
	// contains filtered or unexported fields
}

func (*Flags) Add

func (flags *Flags) Add(f *Flag) error

func (*Flags) GetConfigPath

func (flags *Flags) GetConfigPath() string

func (*Flags) Init

func (flags *Flags) Init(flagSet *flag.FlagSet, arguments []string)

func (*Flags) Process

func (flags *Flags) Process() error

type FlagsUsing

type FlagsUsing int
const (
	FlagsDontUse FlagsUsing = iota
	FlagsUsePredefined
	FlagsUseAll
)

type LoadOptions

type LoadOptions struct {
	Watcher Watcher
	Context context.Context
	Reload  bool
}

type Locations

type Locations struct {
	ApplicationName string
	List            []string
	// contains filtered or unexported fields
}

func NewLocations

func NewLocations(applicationName string, locations ...string) *Locations

func (*Locations) Add

func (l *Locations) Add(locations ...string)

func (*Locations) AddJoin

func (l *Locations) AddJoin(locationParts ...string)

func (*Locations) ExpandLocation

func (l *Locations) ExpandLocation(path string) string

func (*Locations) Init

func (l *Locations) Init(applicationName string, locations ...string) *Locations

func (*Locations) Locate

func (l *Locations) Locate(filename string) (box Box, err error)

func (*Locations) LocatePath

func (l *Locations) LocatePath(filename string) (string, error)

type Locker

type Locker interface {
	Lock()
	Unlock()
}

Locker interface is used for exlusive access to a variable if it realized.

type MarshalFunc

type MarshalFunc func(v interface{}) ([]byte, error)

MarshalFunc is any marshaler.

type Options

type Options struct {
	Flags         Flags
	Enviropment   Enviropment
	Tags          Tags
	DefaultFormat string
}

Config processing options.

type Pantry

type Pantry struct {
	Locations *Locations
	Options   *Options
}

Pantry is used to load config data from different sources.

func NewPantry

func NewPantry(applicationName string, locations ...string) *Pantry

NewPantry creates new Pantry.

func (*Pantry) AddLocation

func (p *Pantry) AddLocation(locationParts ...string)

AddLocation adds searching location.

func (*Pantry) AddLocations

func (p *Pantry) AddLocations(locations ...string)

AddLocations adds searching locations.

func (*Pantry) Box

func (p *Pantry) Box(box Box, v interface{}) error

func (*Pantry) BoxAs

func (p *Pantry) BoxAs(box Box, v interface{}, format string) error

func (*Pantry) BoxWith

func (p *Pantry) BoxWith(box Box, v interface{}, marshaler MarshalFunc) error

func (*Pantry) Decode

func (p *Pantry) Decode(r io.Reader, v interface{}, format string) error

func (*Pantry) Encode

func (p *Pantry) Encode(w io.Writer, v interface{}, format string) error

func (*Pantry) Init

func (p *Pantry) Init(applicationName string, locations ...string) *Pantry

Init Pantry.

func (*Pantry) Load

func (p *Pantry) Load(path string, v interface{}, opt ...func(*LoadOptions)) (Box, error)

func (*Pantry) LoadAs

func (p *Pantry) LoadAs(path string, v interface{}, format string, opts ...func(*LoadOptions)) (Box, error)

func (*Pantry) LoadWith

func (p *Pantry) LoadWith(path string, v interface{}, unmarshaler UnmarshalFunc) (string, error)

func (*Pantry) Locate

func (p *Pantry) Locate(filename string) (Box, error)

Locate looks for the file in previously added locations.

func (*Pantry) LocatePath

func (p *Pantry) LocatePath(filename string) (string, error)

LocatePath looks for the file in previously added locations.

func (*Pantry) Marshal

func (p *Pantry) Marshal(v interface{}, format string) (b []byte, err error)

func (*Pantry) MarshalWith

func (p *Pantry) MarshalWith(v interface{}, marshaler MarshalFunc) (b []byte, err error)

func (*Pantry) Save

func (p *Pantry) Save(path string, v interface{}) (Box, error)

func (*Pantry) SaveAs

func (p *Pantry) SaveAs(path string, v interface{}, format string) (Box, error)

func (*Pantry) SaveWith

func (p *Pantry) SaveWith(path string, v interface{}, marshaler MarshalFunc) (string, error)

func (*Pantry) UnBox

func (p *Pantry) UnBox(box Box, v interface{}) error

func (*Pantry) UnBoxAs

func (p *Pantry) UnBoxAs(box Box, v interface{}, format string) error

func (*Pantry) UnBoxWith

func (p *Pantry) UnBoxWith(box Box, v interface{}, unmarshaler UnmarshalFunc) error

func (*Pantry) Unmarshal

func (p *Pantry) Unmarshal(b []byte, v interface{}, format string) error

Unmarshal unmarshals data as diffened format and applays enviropment variables and command line flags.

func (*Pantry) UnmarshalWith

func (p *Pantry) UnmarshalWith(b []byte, v interface{}, unmarshaler UnmarshalFunc) error

UnmarshalWith unmarshals data by "unmarshaler" and applays enviropment variables and command line flags.

type Tag

type Tag struct {
	Use  bool   // Use tag
	Name string // Name of tag
}

Tag options.

type Tags

type Tags struct {
	Config      Tag
	Flag        Tag
	Env         Tag
	Default     Tag
	Description Tag
}

Tags options.

type URLBox

type URLBox struct {
	// contains filtered or unexported fields
}

URLBox

func NewURLBox

func NewURLBox(url, format string) *URLBox

func (*URLBox) Format

func (ub *URLBox) Format() string

func (*URLBox) Get

func (ub *URLBox) Get() ([]byte, error)

func (*URLBox) Path

func (ub *URLBox) Path() string

func (*URLBox) Set

func (ub *URLBox) Set(data []byte) error

func (*URLBox) Watch

func (ub *URLBox) Watch(task func(err error)) error

func (*URLBox) WatchContext

func (ub *URLBox) WatchContext(ctx context.Context, task func(err error)) error

type UnfoundLocation

type UnfoundLocation string

UnfoundLocation denotes that location is not found.

func (UnfoundLocation) Error

func (str UnfoundLocation) Error() string

Returns the formatted configuration error.

type UnmarshalFunc

type UnmarshalFunc func(data []byte, v interface{}) error

UnmarshalFunc is any unmarshaler.

type UnsupportedConfigError

type UnsupportedConfigError string

UnsupportedConfigError denotes encountering an unsupported configuration filetype.

func (UnsupportedConfigError) Error

func (e UnsupportedConfigError) Error() string

Returns the formatted configuration error.

type UnsupportedFlagTypeError

type UnsupportedFlagTypeError struct {
	// contains filtered or unexported fields
}

func (UnsupportedFlagTypeError) Error

func (e UnsupportedFlagTypeError) Error() string

Returns the formatted configuration error.

type Watcher

type Watcher func(err error)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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