store

package
v4.13.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

JsonCodec implements Codec for encoding/decoding to JSON.

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

YamlCodec implements a Codec for encoding/decoding to YAML

Functions

func Copy

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.

Types

type BundleSetter

type BundleSetter interface {
	SetBundle(string)
}

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

type Codec

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

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

func (s *Directory) Close()

func (*Directory) Closed

func (s *Directory) Closed() bool

func (*Directory) Exists

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

func (*Directory) GetCodec

func (s *Directory) GetCodec() Codec

func (*Directory) Keys

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

func (*Directory) Load

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

func (*Directory) MetaData

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

func (*Directory) Name

func (s *Directory) Name() string

func (*Directory) Open

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

func (*Directory) Prefixes

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

func (*Directory) ReadOnly

func (s *Directory) ReadOnly() bool

func (*Directory) Remove

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

func (*Directory) Save

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

func (*Directory) SetMetaData

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

func (*Directory) SetReadOnly

func (s *Directory) SetReadOnly() bool

func (*Directory) Type

func (d *Directory) Type() string

type File

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

func (*File) Close

func (s *File) Close()

func (*File) Closed

func (s *File) Closed() bool

func (*File) Exists

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

func (*File) GetCodec

func (s *File) GetCodec() Codec

func (*File) Keys

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

func (*File) Load

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

func (*File) MetaData

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

func (*File) Name

func (s *File) Name() string

func (*File) Open

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

func (*File) Prefixes

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

func (*File) ReadOnly

func (s *File) ReadOnly() bool

func (*File) Remove

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

func (*File) Save

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

func (*File) SetMetaData

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

func (*File) SetReadOnly

func (s *File) SetReadOnly() bool

func (*File) Type

func (f *File) Type() string

type Memory

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

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

func (*Memory) Close

func (s *Memory) Close()

func (*Memory) Closed

func (s *Memory) Closed() bool

func (*Memory) Exists

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

func (*Memory) GetCodec

func (s *Memory) GetCodec() Codec

func (*Memory) Keys

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

func (*Memory) Load

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

func (*Memory) MetaData

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

func (*Memory) Name

func (s *Memory) Name() string

func (*Memory) Open

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

func (*Memory) Prefixes

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

func (*Memory) ReadOnly

func (s *Memory) ReadOnly() bool

func (*Memory) Remove

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

func (*Memory) Save

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

func (*Memory) SetMetaData

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

func (*Memory) SetReadOnly

func (s *Memory) SetReadOnly() bool

func (*Memory) Type

func (m *Memory) Type() string

type MetaSaver

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

type NotFound string

NotFound is the "key not found" error type.

func (NotFound) Error

func (n NotFound) Error() string

type ReadOnlySetter

type ReadOnlySetter interface {
	SetReadOnly(bool)
}

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

type StackCannotBeOverridden

type StackCannotBeOverridden string

func (StackCannotBeOverridden) Error

func (s StackCannotBeOverridden) Error() string

type StackCannotOverride

type StackCannotOverride string

func (StackCannotOverride) Error

func (s StackCannotOverride) Error() string

type StackPushError

type StackPushError string

func (StackPushError) Error

func (s StackPushError) Error() string

type StackedStore

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 initially created empty.

func (*StackedStore) Close

func (s *StackedStore) Close()

func (*StackedStore) Closed

func (s *StackedStore) Closed() bool

func (*StackedStore) Exists

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

func (*StackedStore) GetCodec

func (s *StackedStore) GetCodec() Codec

func (*StackedStore) ItemReadOnly

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

func (*StackedStore) Keys

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

func (*StackedStore) Layers

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

func (*StackedStore) Load

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

func (*StackedStore) MetaFor

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

func (*StackedStore) Name

func (s *StackedStore) Name() string

func (*StackedStore) Open

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

func (*StackedStore) Prefixes

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

func (*StackedStore) Push

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 initial 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

func (s *StackedStore) ReadOnly() bool

func (*StackedStore) Remove

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

func (*StackedStore) Save

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

func (*StackedStore) SetReadOnly

func (s *StackedStore) SetReadOnly() bool

func (*StackedStore) Type

func (s *StackedStore) Type() string

type Store

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 separate, flat key/value stores.

func Open

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

type UnWritable string

func (UnWritable) Error

func (u UnWritable) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL