contextdb

package
v0.0.0-...-bb2f907 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2023 License: Apache-2.0 Imports: 13 Imported by: 18

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitializeContextDatabase

func InitializeContextDatabase() error

InitializeContextDatabase sets up the connection to the configured database to allow the application to talk to it.

Types

type ContextDb

type ContextDb interface {
	// Returns nil if db health is good
	HealthCheck() error
	// Puts Json Struct in db with key
	Put(ctx context.Context, key string, value interface{}) error
	// Delete k,v
	Delete(ctx context.Context, key string) error
	// Delete all keys in heirarchy
	DeleteAll(ctx context.Context, key string) error
	// Gets Json Struct from db
	Get(ctx context.Context, key string, value interface{}) error
	// Returns all keys with a prefix
	GetAllKeys(ctx context.Context, path string) ([]string, error)
	// Put values in Etcd DB and check if already present
	PutWithCheck(ctx context.Context, key string, value interface{}) error
}

ContextDb is an interface for accessing the context database

var Db ContextDb

Db interface used to talk a concrete Database connection

func NewEtcdClient

func NewEtcdClient(store *clientv3.Client, c EtcdConfig) (ContextDb, error)

NewEtcdClient function initializes Etcd client

type Etcd

type Etcd interface {
	Put(ctx context.Context, key, val string, opts ...clientv3.OpOption) (*clientv3.PutResponse, error)
	Get(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error)
	Delete(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.DeleteResponse, error)
}

Etcd For Mocking purposes

type EtcdClient

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

EtcdClient for Etcd

func (*EtcdClient) Delete

func (e *EtcdClient) Delete(ctx context.Context, key string) error

Delete values from Etcd DB

func (*EtcdClient) DeleteAll

func (e *EtcdClient) DeleteAll(ctx context.Context, key string) error

DeleteAll keys from Etcd DB

func (*EtcdClient) Get

func (e *EtcdClient) Get(ctx context.Context, key string, value interface{}) error

Get values from Etcd DB and decodes from json

func (*EtcdClient) GetAllKeys

func (e *EtcdClient) GetAllKeys(ctx context.Context, key string) ([]string, error)

GetAllKeys values from Etcd DB

func (*EtcdClient) HealthCheck

func (e *EtcdClient) HealthCheck() error

HealthCheck for checking health of the etcd cluster

func (*EtcdClient) Put

func (e *EtcdClient) Put(ctx context.Context, key string, value interface{}) error

Put values in Etcd DB

func (*EtcdClient) PutWithCheck

func (e *EtcdClient) PutWithCheck(ctx context.Context, key string, value interface{}) error

Put values in Etcd DB and check if already present

type EtcdConfig

type EtcdConfig struct {
	Endpoint string
	CertFile string
	KeyFile  string
	CAFile   string
}

EtcdConfig Configuration values needed for Etcd Client

type MockConDb

type MockConDb struct {
	Items []sync.Map
	sync.Mutex
	Err error
}

func (*MockConDb) Delete

func (c *MockConDb) Delete(ctx context.Context, key string) error

func (*MockConDb) DeleteAll

func (c *MockConDb) DeleteAll(ctx context.Context, key string) error

func (*MockConDb) Get

func (c *MockConDb) Get(ctx context.Context, key string, value interface{}) error

func (*MockConDb) GetAllKeys

func (c *MockConDb) GetAllKeys(ctx context.Context, path string) ([]string, error)

func (*MockConDb) HealthCheck

func (c *MockConDb) HealthCheck() error

func (*MockConDb) Put

func (c *MockConDb) Put(ctx context.Context, key string, value interface{}) error

func (*MockConDb) PutWithCheck

func (c *MockConDb) PutWithCheck(ctx context.Context, key string, value interface{}) error

Jump to

Keyboard shortcuts

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