storage

package
v0.15.7 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Overview

Package storage provide generic interface to interact with storage backend.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound             = errors.New("record not found")
	ErrStreamClosed         = errors.New("record stream closed")
	ErrInvalidServerVersion = status.Error(codes.Aborted, "invalid server version")
)

Errors

Functions

func MatchAny added in v0.11.0

func MatchAny(any *anypb.Any, query string) bool

MatchAny searches any data with a query.

Types

type Backend

type Backend interface {
	// Close closes the backend.
	Close() error
	// Get is used to retrieve a record.
	Get(ctx context.Context, recordType, id string) (*databroker.Record, error)
	// GetAll gets all the records.
	GetAll(ctx context.Context) (records []*databroker.Record, version *databroker.Versions, err error)
	// GetOptions gets the options for a type.
	GetOptions(ctx context.Context, recordType string) (*databroker.Options, error)
	// Lease acquires a lease, or renews an existing one. If the lease is acquired true is returned.
	Lease(ctx context.Context, leaseName, leaseID string, ttl time.Duration) (bool, error)
	// Put is used to insert or update a record.
	Put(ctx context.Context, record *databroker.Record) (serverVersion uint64, err error)
	// SetOptions sets the options for a type.
	SetOptions(ctx context.Context, recordType string, options *databroker.Options) error
	// Sync syncs record changes after the specified version.
	Sync(ctx context.Context, serverVersion, recordVersion uint64) (RecordStream, error)
}

Backend is the interface required for a storage backend.

func NewEncryptedBackend

func NewEncryptedBackend(secret []byte, underlying Backend) (Backend, error)

NewEncryptedBackend creates a new encrypted backend.

type RecordStream added in v0.14.0

type RecordStream interface {
	// Close closes the record stream and releases any underlying resources.
	Close() error
	// Next is called to retrieve the next record. If one is available it will
	// be returned immediately. If none is available and block is true, the method
	// will block until one is available or an error occurs. The error should be
	// checked with a call to `.Err()`.
	Next(block bool) bool
	// Record returns the current record.
	Record() *databroker.Record
	// Err returns any error that occurred while streaming.
	Err() error
}

A RecordStream is a stream of records.

Directories

Path Synopsis
Package inmemory contains an in-memory implementation of the databroker backend.
Package inmemory contains an in-memory implementation of the databroker backend.
Package redis implements the storage.Backend interface for redis.
Package redis implements the storage.Backend interface for redis.

Jump to

Keyboard shortcuts

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