Documentation ¶
Index ¶
- Variables
- func ToBool(in interface{}) (bool, error)
- func ToInt(in interface{}) (int, error)
- func ToInt64(in interface{}) (int64, error)
- func ToInt64E(in interface{}) (int64, error)
- func ToString(in interface{}) (string, error)
- func ToTime(in interface{}) (time.Time, error)
- type ErrorFunc
- type Getter
- type Handler
- type Initer
- type Loader
- type Setter
- type TypeGetterDefault
- type TypeGetterErr
Constants ¶
This section is empty.
Variables ¶
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 ¶
Types ¶
type ErrorFunc ¶
ErrorFunc is the signature of the function to call when using one of the TypeGetterDefault calls and the call detects an error.
type Getter ¶
A Getter retrieves values for keys. It returns true if a value was found, and false otherwise.
type Handler ¶
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 Setter ¶
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.