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

package store

import "github.com/digitalrebar/provision/store"

Index

Package Files

codec.go common.go directory.go file.go hooks.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.

type BundleSetter Uses

type BundleSetter interface {
    SetBundle(string)
}

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

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 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) Exists Uses

func (f *Directory) Exists(prefix, key string) bool

func (*Directory) GetCodec Uses

func (s *Directory) GetCodec() Codec

func (*Directory) Keys Uses

func (d *Directory) Keys(prefix string) ([]string, error)

func (*Directory) Load Uses

func (f *Directory) Load(prefix, key string, val interface{}) 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) Prefixes Uses

func (d *Directory) Prefixes() ([]string, error)

func (*Directory) ReadOnly Uses

func (s *Directory) ReadOnly() bool

func (*Directory) Remove Uses

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

func (*Directory) Save Uses

func (f *Directory) Save(prefix, 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) 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) Exists Uses

func (f *File) Exists(prefix, key string) bool

func (*File) GetCodec Uses

func (s *File) GetCodec() Codec

func (*File) Keys Uses

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

func (*File) Load Uses

func (f *File) Load(prefix, key string, val interface{}) 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) Prefixes Uses

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

func (*File) ReadOnly Uses

func (s *File) ReadOnly() bool

func (*File) Remove Uses

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

func (*File) Save Uses

func (f *File) Save(prefix, 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) Type Uses

func (f *File) Type() string

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) Exists Uses

func (m *Memory) Exists(prefix, key string) bool

func (*Memory) GetCodec Uses

func (s *Memory) GetCodec() Codec

func (*Memory) Keys Uses

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

func (*Memory) Load Uses

func (m *Memory) Load(prefix, key string, val interface{}) 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) Prefixes Uses

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

func (*Memory) ReadOnly Uses

func (s *Memory) ReadOnly() bool

func (*Memory) Remove Uses

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

func (*Memory) Save Uses

func (m *Memory) Save(prefix, 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) 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 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) Exists Uses

func (s *StackedStore) Exists(prefix, key string) bool

func (*StackedStore) GetCodec Uses

func (s *StackedStore) GetCodec() Codec

func (*StackedStore) ItemReadOnly Uses

func (s *StackedStore) ItemReadOnly(prefix, key string) (bool, bool)

func (*StackedStore) Keys Uses

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

func (*StackedStore) Layers Uses

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

func (*StackedStore) Load Uses

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

func (*StackedStore) MetaFor Uses

func (s *StackedStore) MetaFor(prefix, 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) Prefixes Uses

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

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(prefix, key string) error

func (*StackedStore) Save Uses

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

func (*StackedStore) SetReadOnly Uses

func (s *StackedStore) SetReadOnly() bool

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
    // Keys returns the list of keys that this store has in no
    // particular order.
    Keys(string) ([]string, error)
    // Subs returns a map all of the substores for this store.
    Prefixes() ([]string, error)
    // Test to see if a given entry exists
    Exists(string, string) bool
    // Load the data for a particular key
    Load(string, string, interface{}) error
    // Save data for a key
    Save(string, string, interface{}) error
    // Remove a key/value pair.
    Remove(string, 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
* 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 10 packages (graph). Updated 2019-08-11. Refresh now. Tools for package owners.