store: github.com/digitalrebar/store Index | Files

package store

import "github.com/digitalrebar/store"

Index

Package Files

codec.go common.go consul.go directory.go file.go keySaver.go local.go memory.go stack.go

Variables

var DefaultCodec = JsonCodec
var JsonCodec = &codec{
    enc: json.Marshal,
    dec: json.Unmarshal,
    ext: ".json",
}

JsonCodec implements Codec for encoding/decoding to JSON.

var YamlCodec = &codec{
    enc: yaml.Marshal,
    dec: yamlDecode,
    ext: ".yaml",
}

YamlCodec implements a Codec for encoding/decoding to YAML

func Copy Uses

func Copy(dst, src Store) error

Copy copies all of the contents from src to dest, including substores and metadata. If dst starts out empty, then dst will wind up being a clone of src.

func Create Uses

func Create(s Store, k KeySaver) (bool, error)

Create saves k in s, with the caveat that k must not already be present in s. The bool indicates that the object was saved, and the error indicates the last error that occurred.

func Load Uses

func Load(s Store, k KeySaver) (bool, error)

Load fetches the backing value of k from s. The bool indicates whether the value was loaded, and error contains the last error that occurred during the load process.

func Remove Uses

func Remove(s Store, k KeySaver) (bool, error)

Remove removes k from s. The bool indicates whether the value was removed, and the error contains the last error that occurred during the removal process.

func Save Uses

func Save(s Store, k KeySaver) (bool, error)

Save saves k in s, overwriting anything else that may be there. The bool indicates that the object was saved, and the error contains the last error that occurred..

func Update Uses

func Update(s Store, k KeySaver) (bool, error)

Update saves k in s, with the caveat that s must already contain an older version of k. If k implements ChangeHooker, then it will be called with the version that already exists in the backing store.

type AfterDeleteHooker Uses

type AfterDeleteHooker interface {
    KeySaver
    AfterDelete()
}

AfterDeleteHooker is the interface things can satisfy if they want to perform an action after removal from their backing Backend(). AfterDelete() is called after the object has been removed from the Backend().

type AfterSaveHooker Uses

type AfterSaveHooker interface {
    KeySaver
    AfterSave()
}

AfterSaveHooker is the interface things can satisfy if they want to perfrom an action after an object is saved to the Backend(). AfterSave() will be called after the object has been sucessfully saved.

type BeforeDeleteHooker Uses

type BeforeDeleteHooker interface {
    KeySaver
    BeforeDelete() error
}

BeforeDeleteHooker is the interface that things can satisfy if they want to test things before an object is removed from the backing Backend(). BeforeDelete() will be called before the object is removed from the store, and if it returns a non-nil error the object wil not be deleted.

type BeforeSaveHooker Uses

type BeforeSaveHooker interface {
    KeySaver
    BeforeSave() error
}

BeforeSaveHooker is the interface things can satisfy if they want to perform an action just before the object is saved to the Backend(). It is called after any OnCreate() or OnChange() hooks. If BeforeSave returns an error, the object will not be saved to the Backend().

type Bolt Uses

type Bolt struct {
    Path string

    Bucket []byte
    // contains filtered or unexported fields
}

func (*Bolt) Close Uses

func (s *Bolt) Close()

func (*Bolt) Closed Uses

func (s *Bolt) Closed() bool

func (*Bolt) GetCodec Uses

func (s *Bolt) GetCodec() Codec

func (*Bolt) GetSub Uses

func (s *Bolt) GetSub(name string) Store

func (*Bolt) Keys Uses

func (b *Bolt) Keys() ([]string, error)

func (*Bolt) Load Uses

func (b *Bolt) Load(key string, val interface{}) error

func (*Bolt) MakeSub Uses

func (b *Bolt) MakeSub(loc string) (Store, error)

func (*Bolt) MetaData Uses

func (b *Bolt) MetaData() map[string]string

func (*Bolt) Name Uses

func (s *Bolt) Name() string

func (*Bolt) Open Uses

func (b *Bolt) Open(codec Codec) error

func (*Bolt) Parent Uses

func (s *Bolt) Parent() Store

func (*Bolt) ReadOnly Uses

func (s *Bolt) ReadOnly() bool

func (*Bolt) Remove Uses

func (b *Bolt) Remove(key string) error

func (*Bolt) Save Uses

func (b *Bolt) Save(key string, val interface{}) error

func (*Bolt) SetMetaData Uses

func (b *Bolt) SetMetaData(vals map[string]string) error

func (*Bolt) SetReadOnly Uses

func (s *Bolt) SetReadOnly() bool

func (*Bolt) Subs Uses

func (s *Bolt) Subs() map[string]Store

func (*Bolt) Type Uses

func (b *Bolt) Type() string

type BundleSetter Uses

type BundleSetter interface {
    SetBundle(string)
}

When loading an object, the store should set the current owner name.

type ChangeHooker Uses

type ChangeHooker interface {
    KeySaver
    OnChange(KeySaver) error
}

ChangeHooker is the interface that things can satisfy if they want to run a hook against an object that is being Update()'ed. OnChange() will be called against the to-be-saved object before it is saved to the Backend() with a copy of the object as it currently exists in the Backend(). If OnChange() returns a non-nil error, the object will no0t be saved.

type Codec Uses

type Codec interface {
    // Encode takes an object and turns it into a byte array.
    Encode(interface{}) ([]byte, error)
    // Decode takes a byte array and decodes it into an object
    Decode([]byte, interface{}) error
    // Ext is the file extension that should be used for this encoding
    // if we are encoding to a filesystem.
    Ext() string
}

Codec is responsible for encoding and decoding raw Go objects into a serializable form.

type Consul Uses

type Consul struct {
    Client *consul.Client

    BaseKey string
    // contains filtered or unexported fields
}

Consul implements a Store that is backed by the Consul key/value store.

func (*Consul) Close Uses

func (s *Consul) Close()

func (*Consul) Closed Uses

func (s *Consul) Closed() bool

func (*Consul) GetCodec Uses

func (s *Consul) GetCodec() Codec

func (*Consul) GetSub Uses

func (s *Consul) GetSub(name string) Store

func (*Consul) Keys Uses

func (b *Consul) Keys() ([]string, error)

func (*Consul) Load Uses

func (b *Consul) Load(key string, val interface{}) error

func (*Consul) MakeSub Uses

func (b *Consul) MakeSub(prefix string) (Store, error)

func (*Consul) MetaData Uses

func (b *Consul) MetaData() (res map[string]string)

func (*Consul) Name Uses

func (s *Consul) Name() string

func (*Consul) Open Uses

func (c *Consul) Open(codec Codec) error

func (*Consul) Parent Uses

func (s *Consul) Parent() Store

func (*Consul) ReadOnly Uses

func (s *Consul) ReadOnly() bool

func (*Consul) Remove Uses

func (b *Consul) Remove(key string) error

func (*Consul) Save Uses

func (b *Consul) Save(key string, val interface{}) error

func (*Consul) SetMetaData Uses

func (b *Consul) SetMetaData(vals map[string]string) error

func (*Consul) SetReadOnly Uses

func (s *Consul) SetReadOnly() bool

func (*Consul) Subs Uses

func (s *Consul) Subs() map[string]Store

func (*Consul) Type Uses

func (c *Consul) Type() string

type CreateHooker Uses

type CreateHooker interface {
    KeySaver
    OnCreate() error
}

CreateHooker is the interface things can satisfy if they want to perfrom an action before a new object is saved to its backing store. OnCreate() will be called just after Create() verifies that no object with the same Key() is in the Backend(), and if it returns a non-nil error the object will not be saved.

type Directory Uses

type Directory struct {
    Path string
    // contains filtered or unexported fields
}

Directory implements a Store that is backed by a local directory tree.

func (*Directory) Close Uses

func (s *Directory) Close()

func (*Directory) Closed Uses

func (s *Directory) Closed() bool

func (*Directory) GetCodec Uses

func (s *Directory) GetCodec() Codec

func (*Directory) GetSub Uses

func (s *Directory) GetSub(name string) Store

func (*Directory) Keys Uses

func (f *Directory) Keys() ([]string, error)

func (*Directory) Load Uses

func (f *Directory) Load(key string, val interface{}) error

func (*Directory) MakeSub Uses

func (f *Directory) MakeSub(path string) (Store, error)

func (*Directory) MetaData Uses

func (d *Directory) MetaData() (res map[string]string)

func (*Directory) Name Uses

func (s *Directory) Name() string

func (*Directory) Open Uses

func (f *Directory) Open(codec Codec) error

func (*Directory) Parent Uses

func (s *Directory) Parent() Store

func (*Directory) ReadOnly Uses

func (s *Directory) ReadOnly() bool

func (*Directory) Remove Uses

func (f *Directory) Remove(key string) error

func (*Directory) Save Uses

func (f *Directory) Save(key string, val interface{}) error

func (*Directory) SetMetaData Uses

func (d *Directory) SetMetaData(vals map[string]string) error

func (*Directory) SetReadOnly Uses

func (s *Directory) SetReadOnly() bool

func (*Directory) Subs Uses

func (s *Directory) Subs() map[string]Store

func (*Directory) Type Uses

func (d *Directory) Type() string

type File Uses

type File struct {
    Path string
    // contains filtered or unexported fields
}

func (*File) Close Uses

func (s *File) Close()

func (*File) Closed Uses

func (s *File) Closed() bool

func (*File) GetCodec Uses

func (s *File) GetCodec() Codec

func (*File) GetSub Uses

func (s *File) GetSub(name string) Store

func (*File) Keys Uses

func (f *File) Keys() ([]string, error)

func (*File) Load Uses

func (f *File) Load(key string, val interface{}) error

func (*File) MakeSub Uses

func (f *File) MakeSub(path string) (Store, error)

func (*File) MetaData Uses

func (f *File) MetaData() map[string]string

func (*File) Name Uses

func (s *File) Name() string

func (*File) Open Uses

func (f *File) Open(codec Codec) error

func (*File) Parent Uses

func (s *File) Parent() Store

func (*File) ReadOnly Uses

func (s *File) ReadOnly() bool

func (*File) Remove Uses

func (f *File) Remove(key string) error

func (*File) Save Uses

func (f *File) Save(key string, val interface{}) error

func (*File) SetMetaData Uses

func (f *File) SetMetaData(vals map[string]string) error

func (*File) SetReadOnly Uses

func (s *File) SetReadOnly() bool

func (*File) Subs Uses

func (s *File) Subs() map[string]Store

func (*File) Type Uses

func (f *File) Type() string

type KeySaver Uses

type KeySaver interface {
    Prefix() string
    Key() string
    KeyName() string
    New() KeySaver
}

KeySaver is the interface that should be satisfied by anything that wants to use the generic CRUD functions that the Store package provides in the keySaver.go file. The methods that should be implemented are:

Prefix() should return something that can be used to disambiguate object types. It is only used for error generating methods in the store package.

Key() should return a per-Prefix() unique value.

New() should return a fresh uninitialized copy of whatever implements KeySaver.

Backend() should return the store being used to back the object.

func List Uses

func List(s Store, ref KeySaver) ([]KeySaver, error)

List returns a slice of KeySavers, which can then be cast back to whatever type is appropriate by the calling code.

type LoadHooker Uses

type LoadHooker interface {
    KeySaver
    OnLoad() error
}

LoadHooker is the interface that things can satisfy if they want to run a hook against an object each time it is loaded from a Backend(). OnLoad() will be called after the object has been loaded from the Backend().

type Memory Uses

type Memory struct {
    // contains filtered or unexported fields
}

MemoryStore provides an in-memory implementation of Store for testing purposes

func (*Memory) Close Uses

func (s *Memory) Close()

func (*Memory) Closed Uses

func (s *Memory) Closed() bool

func (*Memory) GetCodec Uses

func (s *Memory) GetCodec() Codec

func (*Memory) GetSub Uses

func (s *Memory) GetSub(name string) Store

func (*Memory) Keys Uses

func (m *Memory) Keys() ([]string, error)

func (*Memory) Load Uses

func (m *Memory) Load(key string, val interface{}) error

func (*Memory) MakeSub Uses

func (m *Memory) MakeSub(loc string) (Store, error)

func (*Memory) MetaData Uses

func (m *Memory) MetaData() map[string]string

func (*Memory) Name Uses

func (s *Memory) Name() string

func (*Memory) Open Uses

func (m *Memory) Open(codec Codec) error

func (*Memory) Parent Uses

func (s *Memory) Parent() Store

func (*Memory) ReadOnly Uses

func (s *Memory) ReadOnly() bool

func (*Memory) Remove Uses

func (m *Memory) Remove(key string) error

func (*Memory) Save Uses

func (m *Memory) Save(key string, val interface{}) error

func (*Memory) SetMetaData Uses

func (m *Memory) SetMetaData(vals map[string]string) error

func (*Memory) SetReadOnly Uses

func (s *Memory) SetReadOnly() bool

func (*Memory) Subs Uses

func (s *Memory) Subs() map[string]Store

func (*Memory) Type Uses

func (m *Memory) Type() string

type MetaSaver Uses

type MetaSaver interface {
    Store
    MetaData() map[string]string
    SetMetaData(map[string]string) error
}

MetaSaver is a Store that is capable of of recording metadata about itself.

type NotFound Uses

type NotFound string

NotFound is the "key not found" error type.

func (NotFound) Error Uses

func (n NotFound) Error() string

type ReadOnlySetter Uses

type ReadOnlySetter interface {
    SetReadOnly(bool)
}

When loading an object, the store should set the current readonly state on the object.

type SaveCleanHooker Uses

type SaveCleanHooker interface {
    KeySaver
    SaveClean() KeySaver
}

SaveCleanHooker is the interface things can satisfy if they have parts that should not be persisted. It is called immediately before the object is saved, and after BeforeSaveHooker finshes. It should return a copy of itself that has been "cleaned up".

type StackCannotBeOverridden Uses

type StackCannotBeOverridden string

func (StackCannotBeOverridden) Error Uses

func (s StackCannotBeOverridden) Error() string

type StackCannotOverride Uses

type StackCannotOverride string

func (StackCannotOverride) Error Uses

func (s StackCannotOverride) Error() string

type StackPushError Uses

type StackPushError string

func (StackPushError) Error Uses

func (s StackPushError) Error() string

type StackedStore Uses

type StackedStore struct {
    // contains filtered or unexported fields
}

StackedStore is a store that represents the combination of several stores stacked together. The first store in the stack is the only one that is writable, and the rest are set as read-only. StackedStores are initally created empty.

func (*StackedStore) Close Uses

func (s *StackedStore) Close()

func (*StackedStore) Closed Uses

func (s *StackedStore) Closed() bool

func (*StackedStore) GetCodec Uses

func (s *StackedStore) GetCodec() Codec

func (*StackedStore) GetSub Uses

func (s *StackedStore) GetSub(name string) Store

func (*StackedStore) Keys Uses

func (s *StackedStore) Keys() ([]string, error)

func (*StackedStore) Layers Uses

func (s *StackedStore) Layers() []Store

func (*StackedStore) Load Uses

func (s *StackedStore) Load(key string, val interface{}) error

func (*StackedStore) MakeSub Uses

func (s *StackedStore) MakeSub(st string) (Store, error)

func (*StackedStore) MetaFor Uses

func (s *StackedStore) MetaFor(key string) map[string]string

func (*StackedStore) Name Uses

func (s *StackedStore) Name() string

func (*StackedStore) Open Uses

func (s *StackedStore) Open(codec Codec) error

func (*StackedStore) Parent Uses

func (s *StackedStore) Parent() Store

func (*StackedStore) Push Uses

func (s *StackedStore) Push(layer Store, keysCannotBeOverridden, keysCannotOverride bool) error

Push adds a Store to the stack of stores in this stack. Any Store but the inital one will be marked as read-only. Either the Push call succeeds, or nothing about any of the Stores that are part of the Push operation change and the error contains details about what went wrong.

func (*StackedStore) ReadOnly Uses

func (s *StackedStore) ReadOnly() bool

func (*StackedStore) Remove Uses

func (s *StackedStore) Remove(key string) error

func (*StackedStore) Save Uses

func (s *StackedStore) Save(key string, val interface{}) error

func (*StackedStore) SetReadOnly Uses

func (s *StackedStore) SetReadOnly() bool

func (*StackedStore) Subs Uses

func (s *StackedStore) Subs() map[string]Store

func (*StackedStore) Type Uses

func (s *StackedStore) Type() string

type Store Uses

type Store interface {
    sync.Locker
    RLock()
    RUnlock()
    // Open opens the store for use.
    Open(Codec) error
    // GetCodec returns the codec that the open store uses for marshalling and unmarshalling data
    GetCodec() Codec
    // GetSub fetches an already-existing substore.  nil means there is no such substore.
    GetSub(string) Store
    // MakeSub returns a Store that is subordinate to this one.
    // What exactly that means depends on the simplestore in question,
    // but it should wind up sharing the same backing store (directory,
    // database, etcd cluster, whatever)
    MakeSub(string) (Store, error)
    // Parent fetches the parent of this store, if any.
    Parent() Store
    // Keys returns the list of keys that this store has in no
    // particular order.
    Keys() ([]string, error)
    // Subs returns a map all of the substores for this store.
    Subs() map[string]Store
    // Load the data for a particular key
    Load(string, interface{}) error
    // Save data for a key
    Save(string, interface{}) error
    // Remove a key/value pair.
    Remove(string) error
    // ReadOnly returns whether a store is set to be read-only.
    ReadOnly() bool
    // SetReadOnly sets the store into read-only mode.  This is a
    // one-way operation -- once a store is set to read-only, it
    // cannot be changed back to read-write while the store is open.
    SetReadOnly() bool
    // Close closes the store.  Attempting to perfrom operations on
    // a closed store will panic.
    Close()
    // Closed returns whether or not a store is Closed
    Closed() bool
    // Type is the type of Store this is.
    Type() string
    // Name is the name of Store this is.
    Name() string
}

Store provides an interface for some very basic key/value storage needs. Each Store (including ones created with MakeSub() should operate as seperate, flat key/value stores.

func Open Uses

func Open(locator string) (Store, error)

Open a store via URI style locator. Locators have the following formats:

storeType:path?codec=codecType&ro=false&option=foo for stores that always refer to something local, and

storeType://host:port/path?codec=codecType&ro=false&option=foo for stores that need to talk over the network.

All store types take codec and ro as optional parameters

The following storeTypes are known:

* file, in which path refers to a single local file.
* directory, in which path refers to a top-level directory
* consul, in which path refers to the top key in the kv store.
* bolt, in which path refers to the directory where the Bolt database
  is located.  bolt also takes an optional bucket parameter to specify the
  top-level bucket data is stored in.
* memory, in which path does not mean anything.

type UnWritable Uses

type UnWritable string

func (UnWritable) Error Uses

func (u UnWritable) Error() string

Package store imports 13 packages (graph). Updated 2019-03-07. Refresh now. Tools for package owners.