meta

package
v0.0.0-...-1b9e8c6 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultStore = "local"

DefaultStore defines the default store backend.

Variables

View Source
var (
	// ErrObjectNotFound is returned when there is no object found.
	ErrObjectNotFound = Error{objNotFound, "Object not found"}

	// ErrBucketNotFound returns the error that no bucket found.
	ErrBucketNotFound = Error{bucketNotFound, "Bucket not found"}
)
View Source
var (
	// MetaJSONFile is the default name of json file.
	MetaJSONFile = "meta.json"
)

Functions

func Register

func Register(name string, b Backend)

Register registers a backend to be daemon's store.

Types

type Backend

type Backend interface {
	// meta store contructor.
	New(Config) error

	// Put write key-value into store.
	Put(bucket string, key string, value []byte) error

	// Get read object from store.
	Get(bucket string, key string) ([]byte, error)

	// Remove remove all data of the key.
	Remove(bucket string, key string) error

	// List return all objects with specify bucket.
	List(bucket string) ([][]byte, error)

	// Keys return all keys.
	Keys(bucket string) ([]string, error)

	// Path returns the path with the specified key.
	Path(key string) string
}

Backend is an interface which describes what a store should support.

type Bucket

type Bucket struct {
	Name string
	Type reflect.Type
}

Bucket is a Bucket.

func (*Bucket) NewObject

func (b *Bucket) NewObject() Object

NewObject returns Object.

type Config

type Config struct {
	Driver  string
	Buckets []Bucket
	BaseDir string
}

Config represents the configurations used for metadata store.

type Error

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

Error is a type of error used for meta.

func (Error) Error

func (e Error) Error() string

Error returns the message in MetaError.

func (Error) IsNotfound

func (e Error) IsNotfound() bool

IsNotfound return true if code in MetaError is objNotfound.

type Object

type Object interface {
	Key() string
}

Object is an interface.

type Store

type Store struct {
	Config
	// contains filtered or unexported fields
}

Store defines what a metadata store should be like.

func NewStore

func NewStore(cfg Config) (*Store, error)

NewStore creates a backend storage.

func (*Store) Bucket

func (s *Store) Bucket(name string) *Store

Bucket returns a specific store instance. And name is used to specify the bucket's name that will be write.

func (*Store) Fetch

func (s *Store) Fetch(obj Object) error

Fetch uses to get meta data and decode it into 'obj'.

func (*Store) ForEach

func (s *Store) ForEach(handle func(Object) error) error

ForEach uses to handle every object by sequence.

func (*Store) Get

func (s *Store) Get(key string) (Object, error)

Get uses to get meta data.

func (*Store) GetWithPrefix

func (s *Store) GetWithPrefix(prefix string) ([]Object, error)

GetWithPrefix return objects matching prefix.

func (*Store) Keys

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

Keys returns all keys only.

func (*Store) KeysWithPrefix

func (s *Store) KeysWithPrefix(prefix string) ([]string, error)

KeysWithPrefix return all keys matching prefix.

func (*Store) List

func (s *Store) List() (map[string]Object, error)

List returns all objects as map.

func (*Store) Path

func (s *Store) Path(key string) string

Path returns the path with specified key.

func (*Store) Put

func (s *Store) Put(obj Object) error

Put writes the 'obj' into backend storage.

func (*Store) Remove

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

Remove calls it to remove a object.

Jump to

Keyboard shortcuts

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