store

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBackendNotSupported is thrown when the backend k/v store is not supported by libkv
	ErrBackendNotSupported = errors.New("backend storage not supported yet, please choose one of")
	// ErrCallNotSupported is thrown when a method is not implemented/supported by the current backend
	ErrCallNotSupported = errors.New("the current call is not supported with this backend")
	// ErrNotReachable is thrown when the API cannot be reached for issuing common store operations
	ErrNotReachable = errors.New("api not reachable")
	// ErrCannotLock is thrown when there is an error acquiring a lock on a key
	ErrCannotLock = errors.New("error acquiring the lock")
	// ErrKeyModified is thrown during an atomic operation if the index does not match the one in the store
	ErrKeyModified = errors.New("unable to complete atomic operation, key modified")
	// ErrKeyNotFound is thrown when the key is not found in the store during a Get operation
	ErrKeyNotFound = errors.New("key not found in store")
	// ErrPreviousNotSpecified is thrown when the previous value is not specified for an atomic operation
	ErrPreviousNotSpecified = errors.New("previous K/V pair should be provided for the Atomic operation")
	// ErrKeyExists is thrown when the previous value exists in the case of an AtomicPut
	ErrKeyExists = errors.New("previous K/V pair exists, cannot complete Atomic operation")
)

Functions

func AddStore

func AddStore(store string, init Initialize)

AddStore adds a new store backend

Types

type ClientTLSConfig

type ClientTLSConfig struct {
	CertFile   string
	KeyFile    string
	CACertFile string
}

ClientTLSConfig contains data for a Client TLS configuration in the form the etcd client wants it. Eventually we'll adapt it for ZK and Consul.

type EtcdV3

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

EtcdV3 is the receiver type for the Store interface

func (*EtcdV3) Close

func (s *EtcdV3) Close()

Close closes the client connection

func (*EtcdV3) Delete

func (s *EtcdV3) Delete(ctx context.Context, key string) error

Delete the value at the specified key

func (*EtcdV3) Exists

func (s *EtcdV3) Exists(ctx context.Context, key string) (bool, error)

Exists verifies if a Key exists in the store

func (*EtcdV3) Get

func (s *EtcdV3) Get(ctx context.Context, key string) ([]byte, error)

Get a value given its key

func (*EtcdV3) List

func (s *EtcdV3) List(ctx context.Context, directory string) ([][]byte, error)

List the content of a given prefix

func (*EtcdV3) Put

func (s *EtcdV3) Put(ctx context.Context, key string, value []byte, ttl int64) error

Put a value at the specified key

func (*EtcdV3) Watch

func (s *EtcdV3) Watch(ctx context.Context, key string, stopCh <-chan struct{}) (<-chan []byte, error)

Watch for changes on a key

func (*EtcdV3) WatchTree

func (s *EtcdV3) WatchTree(ctx context.Context, directory string, stopCh <-chan struct{}) (<-chan [][]byte, error)

WatchTree watches for changes on child nodes under a given directory

type Initialize

type Initialize func(addrs []string, options *Options) (Store, error)

Initialize creates a new Store object, initializing the client

type Options

type Options struct {
	ClientTLS         *ClientTLSConfig
	TLS               *tls.Config
	DialTimeout       time.Duration
	Bucket            string
	PersistConnection bool
	Username          string
	Password          string
}

Options contains the options for a storage client

type Store

type Store interface {
	// Put a value at the specified key
	Put(ctx context.Context, key string, value []byte, ttl int64) error

	// Get a value given its key
	Get(ctx context.Context, key string) ([]byte, error)

	// Delete the value at the specified key
	Delete(ctx context.Context, key string) error

	// Exists if a Key exists in the store
	Exists(ctx context.Context, key string) (bool, error)

	// Watch for changes on a key
	Watch(ctx context.Context, key string, stopCh <-chan struct{}) (<-chan []byte, error)

	// WatchTree watches for changes on child nodes under
	// a given directory
	WatchTree(ctx context.Context, directory string, stopCh <-chan struct{}) (<-chan [][]byte, error)

	// List the content of a given prefix
	List(ctx context.Context, directory string) ([][]byte, error)

	// Close the store connection
	Close()
}

Store represents the backend K/V storage Each store should support every call listed here. Or it couldn't be implemented as a K/V backend for libkv

func NewEtcdV3

func NewEtcdV3(addrs []string, conf *Options) (Store, error)

NewEtcdV3 creates a new Etcd client given a list of endpoints and an optional tls config

func NewStore

func NewStore(backend string, addrs []string, options *Options) (Store, error)

NewStore creates an instance of store

Jump to

Keyboard shortcuts

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