Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB interface { // Get gets the value for the given key and loads it into val. // returns the value and nil if it was found, nil and ErrNotFound if it // was not found and another appropriate error otherwise Get(key string, val Model) error // GetAllKeys gets all the keys in the database. returns nil and an appropriate // error if the keys couldn't be fetched GetAllKeys() ([]string, error) // Set sets the value for the given existing key. returns nil if the key // already existed and was successfully set, ErrNotFound if the key didn't // already exist, and another appropriate error otherwise Set(key string, val Model) error // Upsert sets or creates the value for the existing key. returns true and nil // if the key was created on this call, false and nil if the key was not created // but still successfully updated, and false and the appropriate error otherwise Upsert(key string, val Model) (bool, error) }
DB is the interface to the database, a flat key-value store. The idea here is to have multiple different DB implementations. This codebase provides an in-memory database and a (untested) mongo database
func NewInMemoryDB ¶
func NewInMemoryDB() DB
type MongoDB ¶
type MongoDB struct {
// contains filtered or unexported fields
}
MongoDB is a DB implementation that talks to an external MongoDB server. Note: this is UNTESTED code, only to be used as a getting started reference. make sure you test it thouroughly against a real MongoDB server before using it in production
func NewMongoDB ¶
NewMongoDB connects to an external MongoDB server and returns a DB implementation that fronts that connection. call Close() on the returned value when done.
func (*MongoDB) Close ¶
func (m *MongoDB) Close()
Close releases the underlying connections. always call this when completely done with operations, not before.