etc

package
v0.0.0-...-0cb7091 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2021 License: BSD-3-Clause-Clear Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEF_UNIT_MSIZE   = 10
	DEF_DIAL_TIMEOUT = 3 * time.Second // 默认连接超时时间
	DEF_OPT_TIMEOUT  = 3 * time.Second // 默认操作超时时间
)

Variables

View Source
var (
	ErrUnwantReload = errors.New("ErrUnwantReload") // 不需要热加载可以返回此error
)

Functions

func InstallExt

func InstallExt(ctrlName string, mc IMCGeter, conf *clientv3.Config)

安装扩展ETCD控制器

func NewLocker

func NewLocker(name string, custCli ...*clientv3.Client) (sync.Locker, error)

NewLocker creates a sync.Locker backed by an etcd mutex.

func PreUnload

func PreUnload(name string) error

PreUnload 卸载存储

Types

type EWatchEvent

type EWatchEvent int //

=> 监听事件类型

const (
	EWatch_Create EWatchEvent = iota + 1 // 创建
	EWatch_Update                        // 更新
	EWatch_Delete                        // 删除
)

type Etcd

type Etcd struct {
	cto.ControlBase
	// contains filtered or unexported fields
}

 => etcd client control

func Install

func Install(ctrlName string, conf *clientv3.Config) *Etcd

安装默认ETCD控制器

func (*Etcd) Client

func (this *Etcd) Client() *clientv3.Client

Etcd.Cluster return Cluster

func (*Etcd) Content

func (this *Etcd) Content(name string) string

Etcd.Content 存储内容

func (*Etcd) Count

func (this *Etcd) Count() int

Etcd.Count 存储数量

func (*Etcd) Del

func (this *Etcd) Del(key string) error

Etcd.Del Delete the key

func (*Etcd) DelRange

func (this *Etcd) DelRange(prefixKey string) error

Etcd.Del Delete in range' all key

func (*Etcd) Get

func (this *Etcd) Get(key string, rev ...int64) ([]byte, error)

Etcd.Get GET key-value (opt为单参数)

func (*Etcd) GetRange

func (this *Etcd) GetRange(key string, opt ...*GetOpt) (keys []string, values [][]byte, err error)

Etcd.Range GET key-values (opt为单参数)

func (*Etcd) HandleInit

func (this *Etcd) HandleInit()

func (*Etcd) HandleTerm

func (this *Etcd) HandleTerm()

func (*Etcd) HasUnit

func (this *Etcd) HasUnit(name string) int

Etcd.HasUnit 查找消费者

func (*Etcd) LeaseKeepalive

func (this *Etcd) LeaseKeepalive(key, value string, ttl time.Duration) (context.CancelFunc, error)

Etcd.LeaseKeepalive Lease the key will be kept forever

func (*Etcd) Load

func (this *Etcd) Load(name string, storer IStorer) error

Etcd.Load 加载 Etcd store

func (*Etcd) Mount

func (this *Etcd) Mount(source TUnits)

Etcd.Mount 挂在初始化源,在控制器启动的时候一起创建

func (*Etcd) NewMutex

func (this *Etcd) NewMutex(name, prefixKey string) (sync.Locker, error)

func (*Etcd) Overview

func (this *Etcd) Overview() string

Etcd.Content 所有存储概览

func (*Etcd) Set

func (this *Etcd) Set(key, value string, ttl ...time.Duration) error

Etcd.Set SET key-value

func (*Etcd) Setnx

func (this *Etcd) Setnx(key, value string) (success bool, oldValue []byte, err error)

Etcd.Setnx SET if not exists. OP操作一般和事务组合使用起到原子的作用

func (*Etcd) Setox

func (this *Etcd) Setox(key, value, oldValue string) (bool, error)

Etcd.Setnx SET if old value exists. OP操作一般和事务组合使用起到原子的作用

func (*Etcd) Watch

func (this *Etcd) Watch(key string, callBack func(e EWatchEvent, val []byte))

Etcd.Watch Watch a key

func (*Etcd) WatchPrefix

func (this *Etcd) WatchPrefix(prefixKey string, callBack func(e EWatchEvent, key, val []byte))

Etcd.WatchPrefix with prefix key

type GetOpt

type GetOpt struct {
	Prefix bool // Keys with matching prefix.

	RangeEndKey string // Returns the keys in the range [key, end)

	FromKey bool // to be equal or greater than they key in the argument

	Limit int64 // limits the number of results to return

	Rev int64 // Specifies the store revision

	SortOrder  int // specifies the ordering, see etcd.SortOrder
	SortTarget int // specifies the ordering, see etcd.SortTarget

	FirstKey, LastKey bool // gets the lexically first/last key in the request range.
}

type IMCGeter

type IMCGeter interface {
	cto.ICtrlHandler

	// 获取基类配置
	HandleEtcd() *Etcd
}

 => ETCD 对象接口

type IStorer

type IStorer interface {

	// 配置名称
	HandleKey() string

	// 配置加载
	HandleInit(val []byte) error

	// 配置内容
	HandleContent() string

	// 配置热加载[自行保证线程安全,当不需要热加载时可以返回 ErrUnwantReload]
	HandleReload(e EWatchEvent, val []byte) error
}

 => 配置数据接口

func Preload

func Preload(name string, handle IStorer) IStorer

Preload 预加载存储

type Key

type Key struct {
	KEY string // Key的路径
	// contains filtered or unexported fields
}

func (Key) Del

func (k Key) Del() error

Key.Del Delete the key

func (Key) DelRange

func (k Key) DelRange() error

Key.Del Delete in range' all key

func (Key) Empty

func (k Key) Empty() bool

etc.Empty when (KEY == "")

func (Key) Get

func (k Key) Get(rev ...int64) ([]byte, error)

Key.Get GET key-value

func (Key) GetRange

func (k Key) GetRange(opt ...*GetOpt) (keys []string, values [][]byte, err error)

Key.Get GET key-values

func (Key) LeaseKeepalive

func (k Key) LeaseKeepalive(val string, ttl time.Duration) error

Key.LeaseKeepalive Set value and Lease the key will be kept forever

func (Key) Set

func (k Key) Set(val string, ttl ...time.Duration) error

etc.Set SET key-value

func (Key) Setnx

func (k Key) Setnx(val string) (success bool, oldValue []byte, err error)

Key.Setnx SET value if not exists.(atom)

func (Key) Setox

func (k Key) Setox(val, oldValue string) (bool, error)

Key.Setnx SET value if old value exists.(atom)

func (Key) StopLease

func (k Key) StopLease(del ...bool)

Key.StopLease stop lease first need call LeaseKeepalive

func (Key) Valid

func (k Key) Valid() bool

etc.Valid KEY is valid

func (Key) Watch

func (k Key) Watch(callBack func(e EWatchEvent, val []byte))

Key.Watch Watch a key

func (Key) WatchPrefix

func (k Key) WatchPrefix(callBack func(e EWatchEvent, key, val []byte))

Key.WatchPrefix with prefix key

type TUnits

type TUnits []Unit // 支持排序

func (TUnits) Len

func (l TUnits) Len() int

func (TUnits) Less

func (l TUnits) Less(i, j int) bool

func (TUnits) Swap

func (l TUnits) Swap(i, j int)

type Unit

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

func NewUnit

func NewUnit(name string, ster IStorer) Unit

存储结构单元

Jump to

Keyboard shortcuts

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