etcd

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Overview

Package etcd provides an implementation of the Storage interface defined in the Rigel project. It uses the etcd.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EtcdStorage

type EtcdStorage struct {
	Client *clientv3.Client
}

EtcdStorage is implements Rigel's Storage interface using etcd v3 client.

func NewEtcdStorage

func NewEtcdStorage(endpoints []string, config ...clientv3.Config) (*EtcdStorage, error)

NewEtcdStorage creates a new instance of EtcdStorage using the provided endpoints with default settings from the package. If an optional clientv3.Config is supplied, it is used to configure the etcd client, overriding the default settings.

func (*EtcdStorage) Get

func (e *EtcdStorage) Get(ctx context.Context, key string) (string, error)

Get retrieves a value from etcd based on the provided key. The function returns the corresponding value as a string. If the key does not exist in etcd, the function returns an empty string and no error. If an error occurs during the operation, it is returned by the function.

func (*EtcdStorage) GetWithPrefix added in v0.12.0

func (e *EtcdStorage) GetWithPrefix(ctx context.Context, prefix string) (map[string]string, error)

GetWithPrefix retrieves all key-value pairs from etcd where the keys start with the provided prefix.

func (*EtcdStorage) Put

func (e *EtcdStorage) Put(ctx context.Context, key string, value string) error

Put stores a value in etcd at the specified key. The value is also stored as a string. If the key already exists in etcd, its value is updated with the new value. If the key does not exist, a new key-value pair is created in etcd. If an error occurs during the operation, it is returned by the function.

func (*EtcdStorage) StatusCheck added in v0.8.0

func (e *EtcdStorage) StatusCheck(ctx context.Context) error

StatusCheck checks the status of the etcd client. If the function succeeds, we can assume that the connection to the etcd server is working.

func (*EtcdStorage) Watch added in v0.9.0

func (e *EtcdStorage) Watch(ctx context.Context, key string, events chan<- types.Event) error

Watch starts watching for changes to a key or a range of keys in etcd and sends the events to the provided channel. If the key is a prefix that matches multiple keys, it watches all those keys. key: The key to watch for changes events is the channel to send events when the key's value changes

Jump to

Keyboard shortcuts

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