repo

package
v0.0.0-...-f318d61 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrApiNotRunning = errors.New("api not running")
)
View Source
var ErrNotFound error = &dsError{error: errors.New("datastore: key not found"), isNotFound: true}

ErrNotFound is returned by Get and GetSize when a datastore does not map the given key to a value.

Functions

func DiskUsage

func DiskUsage(ctx context.Context, d Datastore) (uint64, error)

DiskUsage checks if a Datastore is a PersistentDatastore and returns its DiskUsage(), otherwise returns 0.

func GetBackedHas

func GetBackedHas(ctx context.Context, ds Read, key Key) (bool, error)

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 GetBackedSize

func GetBackedSize(ctx context.Context, ds Read, key Key) (int, error)

GetBackedSize provides a default Datastore.GetSize implementation. It exists so Datastore.GetSize implementations can use it, like so:

func (*d SomeDatastore) GetSize(key Key) (size int, err error) {
  return GetBackedSize(d, key)
}

func NamespaceType

func NamespaceType(namespace string) string

NamespaceType is the first component of a namespace. `foo` in `foo:bar`

func NamespaceValue

func NamespaceValue(namespace string) string

NamespaceValue returns the last component of a namespace. `baz` in `f:b:baz`

Types

type Batch

type Batch interface {
	Write

	Commit(ctx context.Context) error
}

type Batching

type Batching interface {
	Datastore
	Batch(ctx context.Context) (Batch, error)
}

type CheckedDatastore

type CheckedDatastore interface {
	Datastore

	Check(ctx context.Context) error
}

type Datastore

type Datastore interface {
	Read
	Write
	Sync(ctx context.Context, prefix Key) error
	io.Closer
}

type GCDatastore

type GCDatastore interface {
	Datastore

	CollectGarbage(ctx context.Context) error
}

GCDatastore is an interface that should be implemented by datastores which don't free disk space by just removing data from them.

type Key

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

func KeyWithNamespaces

func KeyWithNamespaces(ns []string) Key

KeyWithNamespaces constructs a key out of a namespace slice.

func NewKey

func NewKey(s string) Key

func RandomKey

func RandomKey() Key

RandomKey returns a randomly (uuid) generated key.

RandomKey()
NewKey("/f98719ea086343f7b71f32ea9d9d521d")

func RawKey

func RawKey(s string) Key

func (Key) BaseNamespace

func (k Key) BaseNamespace() string

BaseNamespace returns the "base" namespace of this key (path.Base(filename))

NewKey("/Comedy/MontyPython/Actor:JohnCleese").BaseNamespace()
"Actor:JohnCleese"

func (Key) Bytes

func (k Key) Bytes() []byte

Bytes returns the string value of Key as a []byte

func (Key) Child

func (k Key) Child(k2 Key) Key

Child returns the `child` Key of this Key.

NewKey("/Comedy/MontyPython").Child(NewKey("Actor:JohnCleese"))
NewKey("/Comedy/MontyPython/Actor:JohnCleese")

func (Key) ChildString

func (k Key) ChildString(s string) Key

ChildString returns the `child` Key of this Key -- string helper.

NewKey("/Comedy/MontyPython").ChildString("Actor:JohnCleese")
NewKey("/Comedy/MontyPython/Actor:JohnCleese")

func (*Key) Clean

func (k *Key) Clean()

Clean up a Key, using path.Clean.

func (Key) Equal

func (k Key) Equal(k2 Key) bool

Equal checks equality of two keys

func (Key) Instance

func (k Key) Instance(s string) Key

Instance returns an "instance" of this type key (appends value to namespace).

NewKey("/Comedy/MontyPython/Actor").Instance("JohnClesse")
NewKey("/Comedy/MontyPython/Actor:JohnCleese")

func (Key) IsAncestorOf

func (k Key) IsAncestorOf(other Key) bool

IsAncestorOf returns whether this key is a prefix of `other`

NewKey("/Comedy").IsAncestorOf("/Comedy/MontyPython")
true

func (Key) IsDescendantOf

func (k Key) IsDescendantOf(other Key) bool

IsDescendantOf returns whether this key contains another as a prefix.

NewKey("/Comedy/MontyPython").IsDescendantOf("/Comedy")
true

func (Key) IsTopLevel

func (k Key) IsTopLevel() bool

IsTopLevel returns whether this key has only one namespace.

func (Key) Less

func (k Key) Less(k2 Key) bool

Less checks whether this key is sorted lower than another.

func (Key) List

func (k Key) List() []string

List returns the `list` representation of this Key.

NewKey("/Comedy/MontyPython/Actor:JohnCleese").List()
["Comedy", "MontyPythong", "Actor:JohnCleese"]

func (Key) MarshalJSON

func (k Key) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface, keys are represented as JSON strings

func (Key) Name

func (k Key) Name() string

Name returns the "name" of this key (field of last namespace).

NewKey("/Comedy/MontyPython/Actor:JohnCleese").Name()
"JohnCleese"

func (Key) Namespaces

func (k Key) Namespaces() []string

Namespaces returns the `namespaces` making up this Key.

NewKey("/Comedy/MontyPython/Actor:JohnCleese").Namespaces()
["Comedy", "MontyPython", "Actor:JohnCleese"]

func (Key) Parent

func (k Key) Parent() Key

Parent returns the `parent` Key of this Key.

NewKey("/Comedy/MontyPython/Actor:JohnCleese").Parent()
NewKey("/Comedy/MontyPython")

func (Key) Path

func (k Key) Path() Key

Path returns the "path" of this key (parent + type).

NewKey("/Comedy/MontyPython/Actor:JohnCleese").Path()
NewKey("/Comedy/MontyPython/Actor")

func (Key) Reverse

func (k Key) Reverse() Key

Reverse returns the reverse of this Key.

NewKey("/Comedy/MontyPython/Actor:JohnCleese").Reverse()
NewKey("/Actor:JohnCleese/MontyPython/Comedy")

func (Key) String

func (k Key) String() string

Strings is the string value of Key

func (Key) Type

func (k Key) Type() string

Type returns the "type" of this key (value of last namespace).

NewKey("/Comedy/MontyPython/Actor:JohnCleese").Type()
"Actor"

func (*Key) UnmarshalJSON

func (k *Key) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface, keys will parse any value specified as a key to a string

type KeySlice

type KeySlice []Key

KeySlice attaches the methods of sort.Interface to []Key, sorting in increasing order.

func (KeySlice) Len

func (p KeySlice) Len() int

func (KeySlice) Less

func (p KeySlice) Less(i, j int) bool

func (KeySlice) Swap

func (p KeySlice) Swap(i, j int)

type PersistentDatastore

type PersistentDatastore interface {
	Datastore

	// DiskUsage returns the space used by a datastore, in bytes.
	DiskUsage(ctx context.Context) (uint64, error)
}

PersistentDatastore is an interface that should be implemented by datastores which can report disk usage.

type Read

type Read interface {
	Get(ctx context.Context, key Key) (value []byte, err error)
	Has(ctx context.Context, key Key) (exists bool, err error)
	GetSize(ctx context.Context, key Key) (size int, err error)
	Query(ctx context.Context, q query.Query) (query.Results, error)
}

type Repo

type Repo interface {
	Config() (*config.Config, error)
	BackupConfig(prefix string) (string, error)
	SetConfig(*config.Config) error
	SetConfigKey(key string, value interface{})
	GetConfigKey(key string) (interface{}, error)
	Datastore() Datastore
	GetStoreSize(context.Context) (uint64, error)
	Keystore() keystore.Keystore
	FileManager() *filestore.FileManager
	ChainManager(networkId string) *quantos.BlockchainManager
	SetAPIAddr(addr ma.Multiaddr) error
	SwarmKey() ([]byte, error)
	io.Closer
}

type ScrubbedDatastore

type ScrubbedDatastore interface {
	Datastore

	Scrub(ctx context.Context) error
}

ScrubbedDatastore is an interface that should be implemented by datastores which want to provide a mechanism to check data integrity and/or error correction.

type TTL

type TTL interface {
	PutWithTTL(ctx context.Context, key Key, value []byte, ttl time.Duration) error
	SetTTL(ctx context.Context, key Key, ttl time.Duration) error
	GetExpiration(ctx context.Context, key Key) (time.Time, error)
}

TTL encapulates the methods that deal with entries with time-to-live.

type TTLDatastore

type TTLDatastore interface {
	Datastore
	TTL
}

TTLDatastore is an interface that should be implemented by datastores that support expiring entries.

type Txn

type Txn interface {
	Read
	Write

	// Commit finalizes a transaction, attempting to commit it to the Datastore.
	// May return an error if the transaction has gone stale. The presence of an
	// error is an indication that the data was not committed to the Datastore.
	Commit(ctx context.Context) error
	// Discard throws away changes recorded in a transaction without committing
	// them to the underlying Datastore. Any calls made to Discard after Commit
	// has been successfully called will have no effect on the transaction and
	// state of the Datastore, making it safe to defer.
	Discard(ctx context.Context)
}

Txn extends the Datastore type. Txns allow users to batch queries and mutations to the Datastore into atomic groups, or transactions. Actions performed on a transaction will not take hold until a successful call to Commit has been made. Likewise, transactions can be aborted by calling Discard before a successful Commit has been made.

type TxnDatastore

type TxnDatastore interface {
	Datastore

	NewTransaction(ctx context.Context, readOnly bool) (Txn, error)
}

TxnDatastore is an interface that should be implemented by datastores that support transactions.

type Write

type Write interface {
	Put(ctx context.Context, key Key, value []byte) error
	Delete(ctx context.Context, key Key) error
}

Jump to

Keyboard shortcuts

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