etcd

package
v2.34.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ElectionPathFxTag is the fx tag for the election path.
	ElectionPathFxTag = "etcd.election-path"
	// EnforceLeaderOnlyFxTag is the fx tag for the enforce leader only flag.
	EnforceLeaderOnlyFxTag = "etcd.enforce-leader-only"
)

Variables

This section is empty.

Functions

func Module

func Module() fx.Option

Module is a fx module that provides etcd client.

Types

type Client

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

Client is a wrapper around etcd client.

func ProvideClient

func ProvideClient(in ClientIn) (*Client, error)

ProvideClient creates a new etcd Client and provides it via Fx.

func (*Client) AddElectionWatcher added in v2.22.0

func (etcdClient *Client) AddElectionWatcher(electionWatcher ElectionWatcher)

AddElectionWatcher adds a watcher for election changes.

func (*Client) Delete added in v2.22.0

func (etcdClient *Client) Delete(key string, opts ...clientv3.OpOption)

Delete deletes the given key.

func (*Client) DeletePrefix added in v2.22.0

func (etcdClient *Client) DeletePrefix(prefix string, opts ...clientv3.OpOption)

DeletePrefix deletes all keys with the given prefix.

func (*Client) DeleteSync added in v2.22.0

func (etcdClient *Client) DeleteSync(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.DeleteResponse, error)

DeleteSync deletes the given key.

func (*Client) ETCDClient added in v2.22.0

func (etcdClient *Client) ETCDClient() *clientv3.Client

ETCDClient returns the underlying ETCD client.

func (*Client) Get added in v2.22.0

func (etcdClient *Client) Get(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error)

Get gets the value for the given key.

func (*Client) IsLeader added in v2.22.0

func (etcdClient *Client) IsLeader() bool

IsLeader returns true if the current node is the leader.

func (*Client) Put added in v2.22.0

func (etcdClient *Client) Put(key, val string, opts ...clientv3.OpOption)

Put puts the given value for the given key with lease.

func (*Client) PutSync added in v2.22.0

func (etcdClient *Client) PutSync(ctx context.Context, key, val string, opts ...clientv3.OpOption) (*clientv3.PutResponse, error)

PutSync puts the given value for the given key.

func (*Client) PutWithExpiry added in v2.22.0

func (etcdClient *Client) PutWithExpiry(key, val string, leaseTTL int, opts ...clientv3.OpOption)

PutWithExpiry puts the given value for the given key and lease duration.

func (*Client) RemoveElectionWatcher added in v2.22.0

func (etcdClient *Client) RemoveElectionWatcher(electionWatcher ElectionWatcher)

RemoveElectionWatcher removes a watcher for election changes.

func (*Client) Txn added in v2.22.0

func (etcdClient *Client) Txn(ctx context.Context) (clientv3.Txn, error)

Txn returns a transaction.

func (*Client) Watch added in v2.22.0

func (etcdClient *Client) Watch(ctx context.Context, key string, opts ...clientv3.OpOption) (clientv3.WatchChan, error)

Watch starts a watch with etcd and returns a channel that will receive events.

type ClientIn

type ClientIn struct {
	fx.In
	Unmarshaller      config.Unmarshaller
	Lifecycle         fx.Lifecycle
	Shutdowner        fx.Shutdowner
	Logger            *log.Logger
	ConfigOverride    *ConfigOverride `optional:"true"`
	ElectionPath      string          `name:"etcd.election-path" optional:"true"`
	EnforceLeaderOnly bool            `name:"etcd.enforce-leader-only" optional:"true"`
}

ClientIn holds parameters for ProvideClient.

type ConfigOverride added in v2.8.0

type ConfigOverride struct {
	PerRPCCredentials credentials.PerRPCCredentials // optional
	Namespace         string                        // required
	OverriderName     string                        // who is providing the override, for logs
	Endpoints         []string                      // required
}

ConfigOverride can be provided by an extension to provide parts of etcd client config directly.

type ElectionWatcher added in v2.22.0

type ElectionWatcher interface {
	OnLeaderStart()
	OnLeaderStop()
}

ElectionWatcher is used for tracking changes to election.

Jump to

Keyboard shortcuts

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