Documentation ¶
Overview ¶
Package datastore provides data store functionality. The data store is kept in memory, but optionally the data store may be saved to a file to provide a perisistent data store. This uses go-cache (https://github.com/pmylund/go-cache) for storing the data.
The methods that set, get, and delete key/value pairs also take a `keyType` argument that specifies what kind of object it is.
Index ¶
- Constants
- Variables
- func CheckForOne(dbhandle Dbhandle, kind string, name string) (int32, error)
- func ChkNilArray(obj interface{})
- func ConnectDB(dbEngine string, params interface{}) (*sql.DB, error)
- func DecodeBlob(data []byte, obj interface{}) error
- func EncodeBlob(obj interface{}) ([]byte, error)
- func EncodeToJSON(obj interface{}) (string, error)
- func WalkMapForNil(r interface{}) interface{}
- type DataStore
- func (ds *DataStore) AllNodeStatuses(nodeName string) ([]interface{}, error)
- func (ds *DataStore) Delete(keyType string, key string)
- func (ds *DataStore) DeleteLogInfo(id int) error
- func (ds *DataStore) DeleteNodeStatus(nodeName string) error
- func (ds *DataStore) Get(keyType string, key string) (interface{}, bool)
- func (ds *DataStore) GetList(keyType string) []string
- func (ds *DataStore) GetLogInfo(id int) (interface{}, error)
- func (ds *DataStore) GetLogInfoList() map[int]interface{}
- func (ds *DataStore) LatestNodeStatus(nodeName string) (interface{}, error)
- func (ds *DataStore) Load(dsFile string) error
- func (ds *DataStore) PurgeLogInfoBefore(id int) (int64, error)
- func (ds *DataStore) Save(dsFile string) error
- func (ds *DataStore) Set(keyType string, key string, val interface{})
- func (ds *DataStore) SetLogInfo(obj interface{}, logID ...int) error
- func (ds *DataStore) SetNodeStatus(nodeName string, obj interface{}, nsID ...int) error
- type Dbhandle
- type ResRow
Constants ¶
const MySQLTimeFormat = "2006-01-02 15:04:05"
Format to use for dates and times for MySQL.
Variables ¶
var Dbh *sql.DB
Dbh is the database handle, shared around.
Functions ¶
func CheckForOne ¶
CheckForOne object of the given type identified by the given name. For this function to work, the underlying table MUST have its primary text identifier be called "name".
func ChkNilArray ¶
func ChkNilArray(obj interface{})
ChkNilArray examines an object, searching for empty slices. When restoring an object from either the in-memory data store after it has been saved to disk, or loading an object from the database with gob encoded data structures, empty slices are encoded as "null" when they're sent out as JSON to the client. This makes the client very unhappy, so those empty slices need to be recreated again. Annoying, but it's how it goes.
func ConnectDB ¶
ConnectDB connects to a database with the database name and a map of connection options. Currently supports MySQL and PostgreSQL.
func DecodeBlob ¶
DecodeBlob decodes the data encoded with EncodeBlob that was stored in the database so it can be loaded back into a goiardi object. The 'obj' in the arguments *must* be the address of the object receiving the blob of data (e.g. datastore.DecodeBlob(data, &obj).
func EncodeBlob ¶
EncodeBlob encodes a slice or map of goiardi object data to save in the database. Pass the object to be encoded in like datastore.EncodeBlob(&foo.Thing).
func EncodeToJSON ¶
EncodeToJSON encodes an object to a JSON string.
func WalkMapForNil ¶
func WalkMapForNil(r interface{}) interface{}
WalkMapForNil walks through the given map, searching for nil slices to create. This does not handle all possible cases, but it *does* handle the cases found with the chef objects in goiardi.
Types ¶
type DataStore ¶
type DataStore struct {
// contains filtered or unexported fields
}
DataStore is the main data store struct, holding the key/value store and list of objects.
func New ¶
func New() *DataStore
New creates a new data store instance, or returns an already created one.
func (*DataStore) AllNodeStatuses ¶ added in v0.8.0
AllNodeStatuses returns a list of all statuses known for the given node from the in-memory data store.
func (*DataStore) DeleteLogInfo ¶
DeleteLogInfo deletes a logged event from the data store.
func (*DataStore) DeleteNodeStatus ¶ added in v0.8.0
DeleteNodeStatus deletes all status reports for a node from the in-memory data store.
func (*DataStore) GetLogInfo ¶
GetLogInfo gets a loginfo by id.
func (*DataStore) GetLogInfoList ¶
GetLogInfoList gets all the log infos currently stored.
func (*DataStore) LatestNodeStatus ¶ added in v0.8.0
LatestNodeStatus returns the latest status for a node from the in-memory data store.
func (*DataStore) PurgeLogInfoBefore ¶
PurgeLogInfoBefore purges all the logged events with an id less than the one given from the data store.
func (*DataStore) SetLogInfo ¶
SetLogInfo sets a loginfo in the data store. Unlike most of these objects, log infos are stored and retrieved by id, since they have no useful names.
type Dbhandle ¶
type Dbhandle interface { Prepare(query string) (*sql.Stmt, error) QueryRow(query string, args ...interface{}) *sql.Row Query(query string, args ...interface{}) (*sql.Rows, error) Exec(query string, args ...interface{}) (sql.Result, error) }
Dbhandle is an interface for db handle types that can execute queries.