etcd

package
v0.0.0-...-baf2d7e Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

====================================================

# Copyright (C)2019 All rights reserved. # # Author : domchan # Email : 814172254@qq.com # File Name : common.go # Created : 2019-04-29 10:56 # Last Modified : 2019-04-29 10:56 # Describe : # # ====================================================

====================================================

# Copyright (C)2019 All rights reserved. # # Author : domchan # Email : 814172254@qq.com # File Name : config.go # Created : 2019-04-29 10:54 # Last Modified : 2019-04-29 10:54 # Describe : # # ====================================================

====================================================

# Copyright (C)2019 All rights reserved. # # Author : domchan # Email : 814172254@qq.com # File Name : etcd.go # Created : 2019-04-29 10:52 # Last Modified : 2019-04-29 10:52 # Describe : # # ====================================================

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientTLSConfig

type ClientTLSConfig struct {
	CertFile   string
	KeyFile    string
	CACertFile string
}

ClientTLSConfig contains data for a Client TLS configuration in the form the etcd client wants it. Eventually we'll adapt it for ZK and Consul.

type Config

type Config struct {
	ConnectionTimeout time.Duration
	Username          string
	Password          string

	CAFile string

	CertFile string
	KeyFile  string
}

Config contains the options for a storage client

type Election

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

Election etcd client

func New

func New(addrs []string, options *Config) (*Election, error)

New Create a new etcd client with the given address list and TLS configuration

func (*Election) Close

func (s *Election) Close() error

Close 释放连接

func (*Election) Delete

func (s *Election) Delete(ctx context.Context, key string) error

Delete key-value

func (*Election) HeartBeat

func (s *Election) HeartBeat() error

HeartBeat check whether connection is available

func (*Election) SetNx

func (s *Election) SetNx(ctx context.Context, key string, value []byte, opts *election.WriteOptions) error

SetNx set key value to etcd if it is not exist, you can set writeoptions to change the default status

func (*Election) Watch

func (s *Election) Watch(ctx context.Context, key string, stopCh <-chan struct{}) (<-chan *election.WatchRes, error)

Watch a key change it returns a change that chan can use to receive the value of the key passing a value to stopch can terminate watch

Jump to

Keyboard shortcuts

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