etcdx

package
v0.0.33 Latest Latest
Warning

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

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

Documentation

Overview

Package etcdx - an extension of etcd library.

Index

Constants

View Source
const (
	KeyEndpoints    = "server.etcd.endpoints"
	KeyDialTimeout  = "server.etcd.dial.timeout"
	KeyReadTimeout  = "server.etcd.read.timeout"
	KeyWriteTimeout = "server.etcd.write.timeout"
)

Variables

This section is empty.

Functions

func Get

func Get[T any](key string) (ret T, _ error)

func GetAllAsMap added in v0.0.13

func GetAllAsMap[T any](prefix string) (map[string]*T, error)

GetAllAsMap - retrieves all KVs matches given prefix and converts to a map[<key>]<value>.

func GetBytes

func GetBytes(key string) ([]byte, error)

GetBytes - retrieves the value of given key in []byte type.

func GetKeys

func GetKeys(prefix string) ([]string, error)

GetKeys - retrieves all keys with given prefix in etcd clusters. Caution: a very short prefix can match a large mount of keys. Please use this function carefully.

func Grant

func Grant(ttl int64) (int64, error)

Grant - calls etcd function to generate a lease to use.

func KeepaliveOnce

func KeepaliveOnce(lease int64) error

KeepaliveOnce - sends keepalive (heartbeat) message to etcd server only once.

func NewClient added in v0.0.7

func NewClient(cfg *Config) (*etcd.Client, error)

NewClient - creates an etcd client with given configuration.

func Put

func Put(key, value string) error

func PutWithLease

func PutWithLease(key, value string, lease int64) error

PutWithLease - writes a KV to etcd with given lease ID.

func PutWithNewLease added in v0.0.7

func PutWithNewLease(key, value string, ttl int64) (int64, error)

PutWithNewLease - writes a KV to etcd with a new granted lease and returns the lease id to caller. The new generated lease will be revoked if errors occurred.

func Revoke added in v0.0.7

func Revoke(lease int64) error

Revoke - revokes/deletes the given lease with the default context and ignore the response.

Types

type Config

type Config struct {
	Endpoints []string

	DialTimeout  time.Duration
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
}
var (
	Cfg    *Config
	DefCfg = &Config{
		DialTimeout:  10 * time.Second,
		ReadTimeout:  10 * time.Second,
		WriteTimeout: 10 * time.Second,
	}
)

type KV

type KV[T any] struct {
	Key   string
	Value *T
}

KV - a struct like etcd.KV struct but store the key/value in string type instead of []byte.

func GetAll added in v0.0.13

func GetAll[T any](prefix string) ([]*KV[T], error)

GetAll - retrieves all KVs matches given prefix and returns an array.

Jump to

Keyboard shortcuts

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