etcd

package
v2.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 {
	*clientv3.Client
	KVWrapper KVWrapper // wraps the same KV as Client
	// contains filtered or unexported fields
}

Client is a wrapper around etcd client v3. It provides interfaces rooted by a namespace in etcd.

Client.Client is nil before OnStart.

func ProvideClient

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

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

type ClientIn

type ClientIn struct {
	fx.In

	Unmarshaller   config.Unmarshaller
	Lifecycle      fx.Lifecycle
	Logger         *log.Logger
	ConfigOverride *ConfigOverride `optional:"true"`
}

ClientIn holds parameters for ProvideClient.

type ConfigOverride added in v2.8.0

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

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

type KVWrapper added in v2.9.0

type KVWrapper struct {
	clientv3.KV
}

KVWrapper wraps clientv3.KV, can be used when wanting to depend on clientv3.KV already before OnStart.

KVWrapper.KV is nil before OnStart.

Note: This is not named just KV not to break .KV field access.

type Session added in v2.9.0

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

Session wraps concurrencyv3.Session.

Session may be available at OnStart, but that's not guaranteed. Session will shutdown the app when it expires.

func ProvideSession added in v2.9.0

func ProvideSession(
	client *Client,
	lc fx.Lifecycle,
	shutdowner fx.Shutdowner,
) (*Session, error)

ProvideSession provides Session.

func (*Session) WaitSession added in v2.10.0

func (s *Session) WaitSession(ctx context.Context) (*concurrencyv3.Session, error)

WaitSession waits (up to context deadline) for etcd session to be established or errors.

type SessionScopedKV added in v2.9.0

type SessionScopedKV struct {
	KVWrapper
}

SessionScopedKV implements clientv3.KV by attaching the session's lease to all Put requests, effectively scoping all created keys to the session.

func ProvideSessionScopedKV added in v2.9.0

func ProvideSessionScopedKV(client *Client, session *Session, lc fx.Lifecycle) *SessionScopedKV

ProvideSessionScopedKV provides SessionScopedKV.

Note: This requires Session, so any usage of SessionScopedKV will cause app to shut down.

Jump to

Keyboard shortcuts

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