Documentation ¶
Overview ¶
Package keystore provides an in memory key/value store service library
Package keystore provides an in memory key/value store service library
Package keystore provides an in memory key/value store service library
Package keystore provides an in memory key/value store service library
Index ¶
- type KeyValueStore
- type Op
- type Request
- type Response
- type Service
- type Store
- func (s *Store) DeleteKey(key string)
- func (s *Store) GetArray(key string) (interface{}, error)
- func (s *Store) GetBool(key string) (interface{}, error)
- func (s *Store) GetFloat(key string) (interface{}, error)
- func (s *Store) GetInt(key string) (interface{}, error)
- func (s *Store) GetMap(key string) (interface{}, error)
- func (s *Store) GetString(key string) (interface{}, error)
- func (s *Store) GetValue(key string) (val interface{}, err error)
- func (s *Store) KeyExists(key string) (exists bool)
- func (s *Store) ReadFromDisk() (err error)
- func (s *Store) SaveToDisk() (err error)
- func (s *Store) SetArray(key string, value interface{}) error
- func (s *Store) SetBool(key string, value interface{}) error
- func (s *Store) SetFloat(key string, value interface{}) error
- func (s *Store) SetInt(key string, value interface{}) error
- func (s *Store) SetMap(key string, value interface{}) error
- func (s *Store) SetString(key string, value interface{}) error
- func (s *Store) SetValue(key string, value interface{}) error
- func (s *Store) UpdateFilePath(filePath string)
- type Sync
- func (s *Sync) DeleteKey(key string)
- func (s *Sync) GetArray(key string) (interface{}, error)
- func (s *Sync) GetBool(key string) (interface{}, error)
- func (s *Sync) GetFloat(key string) (interface{}, error)
- func (s *Sync) GetInt(key string) (interface{}, error)
- func (s *Sync) GetMap(key string) (interface{}, error)
- func (s *Sync) GetString(key string) (interface{}, error)
- func (s *Sync) GetValue(key string) (interface{}, error)
- func (s *Sync) GetValueType(key string, v interface{}) error
- func (s *Sync) SetArray(key string, value interface{}) error
- func (s *Sync) SetBool(key string, value interface{}) error
- func (s *Sync) SetFloat(key string, value interface{}) error
- func (s *Sync) SetInt(key string, value interface{}) error
- func (s *Sync) SetMap(key string, value interface{}) error
- func (s *Sync) SetString(key string, value interface{}) error
- func (s *Sync) SetValue(key string, value interface{}) error
- type Type
- type ValueHolder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KeyValueStore ¶
type KeyValueStore interface { // GetValueType This is used to attempt to parse the value into the interface value provided // See https://golang.org/pkg/encoding/json/#Unmarshal for more information GetValueType(key string, v interface{}) error // GetValue will return the raw value that has been stored GetValue(key string) (interface{}, error) // GetBool returns a bool for the key specified or if the key does not exist // or the value is not of the correct type an error is returned GetBool(key string) (interface{}, error) // GetInt returns an int for the key specified or if the key does not exist // or the value is not of the correct type an error is returned GetInt(key string) (interface{}, error) // GetFloat returns an float for the key specified or if the key does not exist // or the value is not of the correct type an error is returned GetFloat(key string) (interface{}, error) // GetString returns a string for the key specified or if the key does not exist // or the value is not of the correct type an error is returned GetString(key string) (interface{}, error) // GetArray returns an array type for the key specified or if the key does not exist // or the value is not of the correct type an error is returned GetArray(key string) (interface{}, error) // GetMap returns a map type for the key specified or if the key does not exist // or the value is not of the correct type an error is returned GetMap(key string) (interface{}, error) // SetValue will store an arbitrary type value for the key specified SetValue(key string, value interface{}) error // SetBool will store an boolean type value for the key specified SetBool(key string, value interface{}) error // SetInt will store an int type value for the key specified SetInt(key string, value interface{}) error // SetFloat will store a float type value for the key specified SetFloat(key string, value interface{}) error // SetString will store a string type value for the key specified SetString(key string, value interface{}) error // SetArray will store an array type value for the key specified SetArray(key string, value interface{}) error // SetMap will store a map type value for the key specified SetMap(key string, value interface{}) error // DeleteKey will delete the key and value from the store DeleteKey(key string) }
KeyValueStore Defines the interface for a simple key value store type. It can be used by both the server and the clients to provide a uniform API that only differs by the transport method
type Request ¶
type Request struct { Op Op // The operation required Key string // The key (used for all requests) Value *ValueHolder // The request value (used for write requests only) ResponseChannel chan *Response // The return channel }
Request are the requests that will be sent over the channel for operations on the store, such as a read or write
func NewDeleteRequest ¶
NewDeleteRequest will generate a new Request for reading a key
func NewReadRequest ¶
NewReadRequest will generate a new Request for reading a key
func NewWriteRequest ¶
NewWriteRequest will generate a new Request for reading a key
type Response ¶
type Response struct { Success bool // True if the operation was a success (Error may still be present for write and delete operations) Error string // Will contain any errors Value *ValueHolder // The response values }
Response will be returned for each Request containing the result of the operation. If the data type had been specified the value will be contained within the specific value type objects otherwise it will be placed in the arbitrary value field. On a write operation the value returned will be the existing value.
type Service ¶
type Service struct { *Sync // Adopt the sync struct // contains filtered or unexported fields }
Service is the wrapper for the in-memory data store service
func NewService ¶
NewService will initialise a new keystore If filePath is not an empty string the contents of the file will initialise the store and the in-memory values will be written to the store on shutdown
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store creates a new in-memory store that can be read or written to disk
func NewEmptyStore ¶
func NewEmptyStore() *Store
NewEmptyStore creates a new empty Store purely in memory and backed by no store
func NewStoreFromFile ¶
NewStoreFromFile creates a new empty Store that is backed by disk
func (*Store) ReadFromDisk ¶
ReadFromDisk loads the configuration from disk into this Store It returns an error if the data cannot be loaded from disk
func (*Store) SaveToDisk ¶
SaveToDisk will flush the current to disk if their is a valid filepath
func (*Store) UpdateFilePath ¶
UpdateFilePath will update the current file path to allow the data to be saved to that location
type Sync ¶
type Sync struct { // All requests to the store are sent over this channel RequestChannel chan *Request }
Sync implements the KeyValueStore and provides a synchronous blocking API that can be used with the keystore, server and client transports
func (*Sync) GetValueType ¶
GetValueType implements KeyValueStore
type Type ¶
type Type uint
Type allows the requester to specify the type of data it is expecting This allows the caller to either handle the value or the error directly without having to check the type. NONE can be specified meaning any type will be accepted
const ( BOOL Type = 1 << iota // Expecting a boolean INT Type = 1 << iota // Expecting an int FLOAT Type = 1 << iota // Expecting a float STRING Type = 1 << iota // Expecting a string ARRAY Type = 1 << iota // Expecting an array MAP Type = 1 << iota // Expecting a map NONE Type = 1 << iota // Expecting any type )
Flags the data types
type ValueHolder ¶
type ValueHolder struct { Type Type // The data type expected (if read Op) Val interface{} // The arbitrary value if NONE DataType specified }
ValueHolder wraps the value, but if no error the value will be of the type expected