consul

package
v0.0.0-...-276be26 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DIR_TAG   = "etcdv3_dir_$2H#%gRe3*t"
	ROOT_KEY  = "root"
	CONSULAPI = "consulapi" // 一个包装consul自身的服务,为用户提供对consul自身的服务发现能力
)

Variables

This section is empty.

Functions

func Error

func Error(msg string)

func Errorf

func Errorf(fmt string, args ...interface{})

func New

func NewReg

func NewReg() store.Registrar

Types

type Holder

type Holder struct {
	Any interface{}
}

type KVStoreConsul

type KVStoreConsul struct {
	Client *api.Client
	Root   string

	Timeout time.Duration

	ServiceID string
	// contains filtered or unexported fields
}

func (*KVStoreConsul) Acquire

func (s *KVStoreConsul) Acquire(lock *api.Lock,
	withContext func(cancelCtx context.Context),
	doingSth func(*Holder),
	doneFunc func(*Holder),
	doneUnlockedFunc func(*Holder),
	cancelledFunc func(*Holder)) (BlockFunc func())

func (*KVStoreConsul) Close

func (s *KVStoreConsul) Close()

func (*KVStoreConsul) Delete

func (s *KVStoreConsul) Delete(key string) bool

func (*KVStoreConsul) DeletePrefix

func (s *KVStoreConsul) DeletePrefix(keyPrefix string) bool

func (*KVStoreConsul) DeleteTTL

func (s *KVStoreConsul) DeleteTTL(key string) bool

func (*KVStoreConsul) Deregister

func (s *KVStoreConsul) Deregister(serviceName string, id string, ipOrHost net.IP, port int) error

func (*KVStoreConsul) DeregisterAll

func (s *KVStoreConsul) DeregisterAll(serviceName string) error

func (*KVStoreConsul) Exists

func (s *KVStoreConsul) Exists(key string) bool

func (*KVStoreConsul) Get

func (s *KVStoreConsul) Get(key string) string

func (*KVStoreConsul) GetPrefix

func (s *KVStoreConsul) GetPrefix(keyPrefix string) store.KvPairs

func (*KVStoreConsul) GetRootPrefix

func (s *KVStoreConsul) GetRootPrefix() string

func (*KVStoreConsul) GetYaml

func (s *KVStoreConsul) GetYaml(key string) interface{}

func (*KVStoreConsul) IsOpen

func (s *KVStoreConsul) IsOpen() bool

func (*KVStoreConsul) LockObject

func (s *KVStoreConsul) LockObject(key string, value string, sessionTTL string) *api.Lock

Sample: s.Lock("webhook_receiver/1", "something", "10s", ) TTL 在 10s .. 24h 之间,

func (*KVStoreConsul) LockObjectDestroy

func (s *KVStoreConsul) LockObjectDestroy(lock *api.Lock)

func (*KVStoreConsul) NameResolver

func (s *KVStoreConsul) NameResolver(serviceName, ver, what string) (net.IP, uint16, string)

NameResolver 返回第一个可用服务的 SVR 记录 return net.IPv4zero, 0 means there are no more targets to be found

func (*KVStoreConsul) NameResolverAll

func (s *KVStoreConsul) NameResolverAll(serviceName string, what string) (sr []*store.ServiceRecord)

NameResolverAll 返回当前的全部可用服务记录列表

func (*KVStoreConsul) Put

func (s *KVStoreConsul) Put(key string, value string) error

func (*KVStoreConsul) PutLite

func (s *KVStoreConsul) PutLite(key string, value string) error

func (*KVStoreConsul) PutNX

func (s *KVStoreConsul) PutNX(key string, value string) error

func (*KVStoreConsul) PutTTL

func (s *KVStoreConsul) PutTTL(key string, value string, seconds int64) error

TTL 在 10s .. 24h 之间, 在 DeleteTTL() 调用之前,即使超时key也不会被K/V Store所删除,注意这一点,这并不是etcd类似的TTL特性。 也就是说,除非将隐含的lock对象Unlock了,才会删除对应的key值; 同时,也要注意到除非隐含的lock对象被lock住,才会创建对应的key值;

func (*KVStoreConsul) PutTTLLite

func (s *KVStoreConsul) PutTTLLite(key string, value string, seconds int64) error

func (*KVStoreConsul) PutYaml

func (s *KVStoreConsul) PutYaml(key string, value interface{}) error

func (*KVStoreConsul) PutYamlLite

func (s *KVStoreConsul) PutYamlLite(key string, value interface{}) error

func (*KVStoreConsul) QueryService

func (s *KVStoreConsul) QueryService(name string) ([]*api.CatalogService, error)

func (*KVStoreConsul) Register

func (s *KVStoreConsul) Register(serviceName, id, version string, ipOrHost net.IP, port int, ttl int64, tags []string, meta map[string]interface{}, moreChecks api.AgentServiceChecks) error

func (*KVStoreConsul) SetDebug

func (s *KVStoreConsul) SetDebug(enabled bool)

func (*KVStoreConsul) SetRoot

func (s *KVStoreConsul) SetRoot(keyPrefix string)

func (*KVStoreConsul) Unlock

func (s *KVStoreConsul) Unlock(lock *api.Lock)

func (*KVStoreConsul) Watch

func (s *KVStoreConsul) Watch(key string, fn store.WatchFunc, stopCh chan bool) (blockFunc func())

Watch

func (*KVStoreConsul) WatchPrefix

func (s *KVStoreConsul) WatchPrefix(keyPrefix string, fn store.WatchFunc, stopCh chan bool) func()

WatchPrefix

type MyKvPair

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

func (*MyKvPair) Key

func (s *MyKvPair) Key() string

func (*MyKvPair) Value

func (s *MyKvPair) Value() []byte

func (*MyKvPair) ValueString

func (s *MyKvPair) ValueString() string

type MyKvPairs

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

func (*MyKvPairs) Count

func (s *MyKvPairs) Count() int

func (*MyKvPairs) Item

func (s *MyKvPairs) Item(index int) store.KvPair

type OpFunc

type OpFunc func(c *api.Client, clientIP net.IP, clientPort int) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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