etcd

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package etcd defines EtcdClient interface, and use "go.etcd.io/etcd/client/v3" implements the interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientProperties

type ClientProperties struct {
	Endpoints          []string
	UserName           string
	Password           string
	NeedAuthentication bool
	ClientCert         string
	ClientKey          string
	CaCert             string
}

ClientProperties properties for etcd

type EtcdClient

type EtcdClient interface {
	Get(key string) (string, error)
	Put(key, value string) (string, error)
	List(prefix string) ([]*KeyValue, error)
	Del(key string) (int64, error)
	Watch(prefix string, startIndex int64, onEvent func(event *clientv3.Event))
	Close() error
}

func CreateEtcdClient

func CreateEtcdClient(etcdConfiguration *EtcdConfiguration) EtcdClient

CreateEtcdClient according to yaml etcdConfiguration

type EtcdConfiguration

type EtcdConfiguration struct {
	APIVersion  string `yaml:"apiVersion"`
	Address     string `yaml:"address"`
	Username    string `yaml:"username"`
	Password    string `yaml:"password"`
	HTTPSEnable bool   `yaml:"httpsEnable"`
	ClientCert  string `yaml:"clientCert"` // etcd cert file
	ClientKey   string `yaml:"clientKey"`  // etcd cert-key file
	CaCert      string `yaml:"caCert"`     // etcd ca file
}

EtcdConfiguration yaml etcd configuration entity

type EtcdV3Client

type EtcdV3Client struct {
	*clientv3.Client
}

EtcdV3Client implements EtcdClient interface.

func NewEtcdV3Client

func NewEtcdV3Client(props *ClientProperties) (*EtcdV3Client, error)

NewEtcdV3Client create an *EtcdV3Client based on "go.etcd.io/etcd/client/v3"

func (*EtcdV3Client) Close

func (c *EtcdV3Client) Close() error

func (*EtcdV3Client) Del

func (c *EtcdV3Client) Del(key string) (int64, error)

Del delete the key which in etcd

func (*EtcdV3Client) Get

func (c *EtcdV3Client) Get(key string) (string, error)

Get return the val corresponding to the key in etcd

func (*EtcdV3Client) List

func (c *EtcdV3Client) List(prefix string) ([]*KeyValue, error)

List return a list key-val from etcd with prefix

func (*EtcdV3Client) Put

func (c *EtcdV3Client) Put(key, value string) (string, error)

Put store key-value in etcd

func (*EtcdV3Client) Watch

func (c *EtcdV3Client) Watch(prefix string, startIndex int64, onEvent func(event *clientv3.Event))

Watch monitor active_key changes

type KeyValue

type KeyValue struct {
	Key           string
	Val           string
	ModifiedIndex int64
}

KeyValue is etcd-Kv Simplified version

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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