cfg

package
v0.0.0-...-ed5747a Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2018 License: MIT Imports: 5 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadType conversion of value to specified type failed.
	ErrBadType = errors.New("bad type conversion")

	// ErrKeyNotFound specified key not found.
	ErrKeyNotFound = errors.New("key not found")

	// ErrKeyNotSet key could not be set to value
	ErrKeyNotSet = errors.New("key not set")

	// ErrArgsNotSupported set and/or get routine don't support extra arguments
	ErrArgsNotSupported = errors.New("args not supported")

	// ErrBadArgs args passed in are bad
	ErrBadArgs = errors.New("bad args")
)

Functions

func ToBool

func ToBool(in interface{}) (bool, error)

ToBool converts in to a bool value.

func ToInt

func ToInt(in interface{}) (int, error)

ToInt converts in to a int value.

func ToInt64

func ToInt64(in interface{}) (int64, error)

ToInt64 converts in to an int value

func ToInt64E

func ToInt64E(in interface{}) (int64, error)

ToInt64E is the same as cast.ToIntE, except it returns a 64 bit int.

func ToString

func ToString(in interface{}) (string, error)

ToString converts in to a string value.

func ToTime

func ToTime(in interface{}) (time.Time, error)

ToTime converts in to a time.Time value.

Types

type ErrorFunc

type ErrorFunc func(key string, err error, args ...interface{})

ErrorFunc is the signature of the function to call when using one of the TypeGetterDefault calls and the call detects an error.

type Getter

type Getter interface {
	Get(key string, args ...interface{}) (interface{}, error)
}

A Getter retrieves values for keys. It returns true if a value was found, and false otherwise.

type Handler

type Handler interface {
	Initer
	Getter
	Setter
	Args() bool
}

A Handler defines the interface to different types of stores. The Init method should always be called before attempting to get or set values for a handler.

type Initer

type Initer interface {
	Init() error
}

A Initer initializes a data structure.

type Loader

type Loader interface {
	Load(out interface{}) error
}

A Loader loads values into out.

type Setter

type Setter interface {
	Set(key string, value interface{}, args ...interface{}) error
}

A Setter stores a value for a key. It returns nil on success and ErrKeyNotSet on failure.

type TypeGetterDefault

type TypeGetterDefault interface {
	GetInt(key string, args ...interface{}) int        // return 0 when error occurs
	GetString(key string, args ...interface{}) string  // return "" when error occurs
	GetTime(key string, args ...interface{}) time.Time // return empty time.Time when error occurs
	GetBool(key string, args ...interface{}) bool      // return false when error occurs
	GetLastError() error                               // Return last error from above Gets
	SetErrorHandler(f ErrorFunc)                       // Called when one of the above Gets sees an error
}

TypeGetterDefault performs type safe conversion and retrieval of key values. The routines mask the error and instead return a default value if an error did occur. You can check for the error by calling GetLastError. Alternatively you can call SetErrorHandler to a function to call when one of the getters sees an error.

type TypeGetterErr

type TypeGetterErr interface {
	GetIntErr(key string, args ...interface{}) (int, error)
	GetStringErr(key string, args ...interface{}) (string, error)
	GetTimeErr(key string, args ...interface{}) (time.Time, error)
	GetBoolErr(key string, args ...interface{}) (bool, error)
}

A TypeGetterErr performs type safe conversion and retrieval of key values. The routines have return ErrBadType if the value doesn't match or can't be converted to the getter method called. ErrKeyNotFound is returned if the specified key is not found.

Jump to

Keyboard shortcuts

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