Documentation ¶
Index ¶
- Variables
- func GetBackedHas(ds Datastore, key Key) (bool, error)
- func NamespaceType(namespace string) string
- func NamespaceValue(namespace string) string
- type Datastore
- type Key
- func (k Key) BaseNamespace() string
- func (k Key) Bytes() []byte
- func (k Key) Child(s string) Key
- func (k *Key) Clean()
- func (k Key) Instance(s string) Key
- func (k Key) IsAncestorOf(other Key) bool
- func (k Key) IsDescendantOf(other Key) bool
- func (k Key) IsTopLevel() bool
- func (k Key) List() []string
- func (k Key) Name() string
- func (k Key) Namespaces() []string
- func (k Key) Parent() Key
- func (k Key) Path() Key
- func (k Key) Reverse() Key
- func (k Key) String() string
- func (k Key) Type() string
- type LogDatastore
- type MapDatastore
- type NullDatastore
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidType = errors.New("datastore: invalid type error.")
ErrInvalidType is returned by Put when a given value is incopatible with the type the datastore supports. This means a conversion (or serialization) is needed beforehand.
var ErrNotFound = errors.New("datastore: key not found.")
ErrNotFound is returned by Get, Has, and Delete when a datastore does not map the given key to a value.
Functions ¶
func GetBackedHas ¶
GetBackedHas provides a default Datastore.Has implementation. It exists so Datastore.Has implementations can use it, like so:
func (*d SomeDatastore) Has(key Key) (exists bool, err error) { return GetBackedHas(d, key) }
func NamespaceType ¶
func NamespaceValue ¶
Types ¶
type Datastore ¶
type Datastore interface { // Put stores the object `value` named by `key`. // // The generalized Datastore interface does not impose a value type, // allowing various datastore middleware implementations (which do not // handle the values directly) to be composed together. // // Ultimately, the lowest-level datastore will need to do some value checking // or risk getting incorrect values. It may also be useful to expose a more // type-safe interface to your application, and do the checking up-front. Put(key Key, value interface{}) (err error) // Get retrieves the object `value` named by `key`. // Get will return ErrNotFound if the key is not mapped to a value. Get(key Key) (value interface{}, err error) // Has returns whether the `key` is mapped to a `value`. // In some contexts, it may be much cheaper only to check for existence of // a value, rather than retrieving the value itself. (e.g. HTTP HEAD). // The default implementation is found in `GetBackedHas`. Has(key Key) (exists bool, err error) // Delete removes the value for given `key`. Delete(key Key) (err error) // Returns a list of keys in the datastore KeyList() ([]Key, error) }
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
A Key represents the unique identifier of an object. Our Key scheme is inspired by file systems and Google App Engine key model.
Keys are meant to be unique across a system. Keys are hierarchical, incorporating more and more specific namespaces. Thus keys can be deemed 'children' or 'ancestors' of other keys::
Key("/Comedy") Key("/Comedy/MontyPython")
Also, every namespace can be parametrized to embed relevant object information. For example, the Key `name` (most specific namespace) could include the object type::
Key("/Comedy/MontyPython/Actor:JohnCleese") Key("/Comedy/MontyPython/Sketch:CheeseShop") Key("/Comedy/MontyPython/Sketch:CheeseShop/Character:Mousebender")
func RandomKey ¶
func RandomKey() Key
Returns a randomly (uuid) generated key. RandomKey() NewKey("/f98719ea086343f7b71f32ea9d9d521d")
func (Key) BaseNamespace ¶
Returns the "base" namespace of this key (like path.Base(filename)) NewKey("/Comedy/MontyPython/Actor:JohnCleese").BaseNamespace() "Actor:JohnCleese"
func (Key) Child ¶
Returns the `child` Key of this Key. NewKey("/Comedy/MontyPython").Child("Actor:JohnCleese") NewKey("/Comedy/MontyPython/Actor:JohnCleese")
func (Key) Instance ¶
Returns an "instance" of this type key (appends value to namespace). NewKey("/Comedy/MontyPython/Actor:JohnCleese").List() "JohnCleese"
func (Key) IsAncestorOf ¶
Returns whether this key is an ancestor of `other` NewKey("/Comedy").IsAncestorOf("/Comedy/MontyPython") true
func (Key) IsDescendantOf ¶
Returns whether this key is a descendent of `other` NewKey("/Comedy/MontyPython").IsDescendantOf("/Comedy") true
func (Key) IsTopLevel ¶
func (Key) List ¶
Returns the `list` representation of this Key. NewKey("/Comedy/MontyPython/Actor:JohnCleese").List() ["Comedy", "MontyPythong", "Actor:JohnCleese"]
func (Key) Name ¶
Returns the "name" of this key (field of last namespace). NewKey("/Comedy/MontyPython/Actor:JohnCleese").List() "Actor"
func (Key) Namespaces ¶
Returns the `namespaces` making up this Key. NewKey("/Comedy/MontyPython/Actor:JohnCleese").List() ["Comedy", "MontyPythong", "Actor:JohnCleese"]
func (Key) Parent ¶
Returns the `parent` Key of this Key. NewKey("/Comedy/MontyPython/Actor:JohnCleese").Parent() NewKey("/Comedy/MontyPython")
func (Key) Path ¶
Returns the "path" of this key (parent + type). NewKey("/Comedy/MontyPython/Actor:JohnCleese").Path() NewKey("/Comedy/MontyPython/Actor")
type LogDatastore ¶
LogDatastore logs all accesses through the datastore.
func NewLogDatastore ¶
func NewLogDatastore(ds Datastore, name string) *LogDatastore
func (*LogDatastore) Delete ¶
func (d *LogDatastore) Delete(key Key) (err error)
func (*LogDatastore) Get ¶
func (d *LogDatastore) Get(key Key) (value interface{}, err error)
func (*LogDatastore) KeyList ¶
func (d *LogDatastore) KeyList() ([]Key, error)
func (*LogDatastore) Put ¶
func (d *LogDatastore) Put(key Key, value interface{}) (err error)
type MapDatastore ¶
type MapDatastore struct {
// contains filtered or unexported fields
}
func NewMapDatastore ¶
func NewMapDatastore() (d *MapDatastore)
func (*MapDatastore) Delete ¶
func (d *MapDatastore) Delete(key Key) (err error)
func (*MapDatastore) Get ¶
func (d *MapDatastore) Get(key Key) (value interface{}, err error)
func (*MapDatastore) KeyList ¶
func (d *MapDatastore) KeyList() ([]Key, error)
func (*MapDatastore) Put ¶
func (d *MapDatastore) Put(key Key, value interface{}) (err error)
type NullDatastore ¶
type NullDatastore struct { }
NullDatastore stores nothing, but conforms to the API. Useful to test with.
func NewNullDatastore ¶
func NewNullDatastore() *NullDatastore
func (*NullDatastore) Delete ¶
func (d *NullDatastore) Delete(key Key) (err error)
func (*NullDatastore) Get ¶
func (d *NullDatastore) Get(key Key) (value interface{}, err error)
func (*NullDatastore) KeyList ¶
func (d *NullDatastore) KeyList() ([]Key, error)
func (*NullDatastore) Put ¶
func (d *NullDatastore) Put(key Key, value interface{}) (err error)