goo_etcd

package
v1.0.45 Latest Latest
Warning

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

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

README

goo-etcd

set/get

var cfg = goo_etcd.Config{
    User: "test",
    Password: "123456",
    Endpoints: []string{"localhost:23791", "localhost:23792", "localhost:23793"},
}

func init() {
	goo_etcd.Init(cfg)
}

func main() {
	key := "/test/proj.com/grpc-user/v100"
	val := "hnatao"

	goo_etcd.Set(key, val, 0)

	goo_log.Debug(goo_etcd.Get(key))
}

GetMap

var cfg = goo_etcd.Config{
    User: "test",
    Password: "123456",
    Endpoints: []string{"localhost:23791", "localhost:23792", "localhost:23793"},
}

func init() {
	goo_etcd.Init(cfg)
}

func main() {
	key := "/test/proj.com/grpc-user"

	key1 := "/test/proj.com/grpc-user/v100"
	val1 := "hnatao-1"

	key2 := "/test/proj.com/grpc-user/v101"
	val2 := "hnatao-2"

	goo_etcd.Set(key1, val1, 0)
	goo_etcd.Set(key2, val2, 0)

	goo_log.Debug(goo_etcd.GetMap(key))
}

GetArray

var cfg = goo_etcd.Config{
    User: "test",
    Password: "123456",
    Endpoints: []string{"localhost:23791", "localhost:23792", "localhost:23793"},
}

func init() {
	goo_etcd.Init(cfg)
}

func main() {
	key := "/test/proj.com/grpc-user"

	key1 := "/test/proj.com/grpc-user/v100"
	val1 := "hnatao-1"

	key2 := "/test/proj.com/grpc-user/v101"
	val2 := "hnatao-2"

	goo_etcd.Set(key1, val1, 0)
	goo_etcd.Set(key2, val2, 0)

	goo_log.Debug(goo_etcd.GetArray(key))
}

SetWithKeepAlive

var cfg = goo_etcd.Config{
    User: "test",
    Password: "123456",
    Endpoints: []string{"localhost:23791", "localhost:23792", "localhost:23793"},
}

func init() {
	goo_etcd.Init(cfg)
}

func main() {
	key := "/test/proj.com/grpc-user/v100"
	val := "hnatao-1"

	goo_etcd.SetWithKeepAlive(key, val, 15)

	goo_utils.AsyncFunc(func() {
		for {
			select {
			case <-goo_context.Cancel().Done():
				return
			default:
				goo_log.Debug(goo_etcd.Get(key))
				time.Sleep(time.Second)
			}
		}
	})

	<-goo_context.Timeout(20 * time.Second).Done()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Del

func Del(key string) error

func Get

func Get(key string) string

func GetArray

func GetArray(key string) (data []string)

func GetMap

func GetMap(key string) (data map[string]string)

func Init

func Init(cfg Config)

func Set

func Set(key, val string, ttl int64) (err error)

func SetWithKeepAlive

func SetWithKeepAlive(key, val string, ttl int64) (err error)

func Watch

func Watch(key string, fn func(arr []string))

Types

type Client

type Client struct {
	*clientv3.Client
	// contains filtered or unexported fields
}

func CLI

func CLI() *Client

func New

func New(cfg Config) (cli *Client, err error)

func (*Client) Del

func (cli *Client) Del(key string) (err error)

func (*Client) Get

func (cli *Client) Get(key string) string

func (*Client) GetArray

func (cli *Client) GetArray(key string) (data []string)

func (*Client) GetMap

func (cli *Client) GetMap(key string) (data map[string]string)

func (*Client) Set

func (cli *Client) Set(key, val string, ttl int64) (err error)

func (*Client) SetWithKeepAlive

func (cli *Client) SetWithKeepAlive(key, val string, ttl int64) (err error)

func (*Client) Watch

func (cli *Client) Watch(key string, fn func([]string))

type Config

type Config struct {
	User      string
	Password  string
	TLS       *TLS
	Endpoints []string
}

type TLS

type TLS struct {
	CertFile string
	KeyFile  string
	CAFile   string
}

Jump to

Keyboard shortcuts

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