Documentation ¶
Index ¶
- Constants
- Variables
- func IsNotFindError(err error) bool
- func NewEtcd(ver int, urls string) dbaccessor.DbAccessor
- func NewEtcdWithRetry(ver int, urls string) dbaccessor.DbAccessor
- type DbRecords
- type Etcd
- func (self *Etcd) DeleteDir(url string) error
- func (self *Etcd) DeleteLeaf(k string) error
- func (self *Etcd) Lock(k string) bool
- func (self *Etcd) ReadDir(k string) ([]*client.Node, error)
- func (self *Etcd) ReadLeaf(k string) (string, error)
- func (self *Etcd) SaveLeaf(k, v string) error
- func (self *Etcd) Unlock(k string) bool
- func (self *Etcd) WatcherDir(url string) (*client.Response, error)
- type EtcdV3
- func (self *EtcdV3) DeleteDir(k string) error
- func (self *EtcdV3) DeleteLeaf(k string) error
- func (self *EtcdV3) Lock(k string) bool
- func (self *EtcdV3) ReadDir(dir string) ([]*client.Node, error)
- func (self *EtcdV3) ReadDirV3(k string) (*DbRecords, error)
- func (self *EtcdV3) ReadLeaf(k string) (string, error)
- func (self *EtcdV3) SaveLeaf(k, v string) error
- func (self *EtcdV3) Unlock(k string) bool
- func (self *EtcdV3) WatcherDir(k string) (*client.Response, error)
- type KvPair
Constants ¶
View Source
const ( MAXTIME = 5 DefaultEtcdAPIVersion = 2 EtcdInitRetryIntervalInSec = 10 )
Variables ¶
View Source
var ( ErrKeyNotFound = errors.New("100: Key not found") ErrTooManyRecordsFound = errors.New("too many records found") )
Functions ¶
func IsNotFindError ¶
func NewEtcdWithRetry ¶
Types ¶
type Etcd ¶
type Etcd struct {
// contains filtered or unexported fields
}
func (*Etcd) DeleteDir ¶
func (self *Etcd) DeleteDir(url string) error { opt := client.DeleteOptions{} opt.Dir = true opt.Recursive = true klog.Info("del ETCD: key[", url, "]") _, err := self.client.Delete(context.Background(), url, &opt) if err != nil { klog.Error("deleteDir:Delete error!", err) return err } return nil }
func (*Etcd) DeleteLeaf ¶
func (self *Etcd) DeleteLeaf(k string) error { klog.Info("del ETCD: key[", k, "]") _, err := self.client.Delete(context.Background(), k, nil) if err != nil { klog.Error("deleteLeaf: Delete error!", err) return err } return nil }
func (*Etcd) ReadLeaf ¶
func (self *Etcd) ReadLeaf(k string) (string, error) { klog.Info("get ETCD: key[", k, "]") rsp, err := self.client.Get(context.Background(), k, nil) if err != nil { klog.Error(err) return "", err } return rsp.Node.Value, nil }
func (*Etcd) SaveLeaf ¶
func (self *Etcd) SaveLeaf(k, v string) error { klog.Info("add ETCD: key[", k, "]value[", v, "]") _, err := self.client.Set(context.Background(), k, v, nil) if err != nil { klog.Error("SaveLeaf",err) return err } return nil }
func (*Etcd) WatcherDir ¶
func (self *Etcd) WatcherDir(url string) (*client.Response, error) { opts := client.WatcherOptions{ Recursive: true, AfterIndex: 0, } //klog.Info("watch ETCD dir [", url, "]") got := self.client.Watcher(url, &opts) resp, err := got.Next(context.Background()) if err != nil { klog.Error(err) return nil,err } return resp,nil }
type EtcdV3 ¶
type EtcdV3 struct {
// contains filtered or unexported fields
}
func (*EtcdV3) DeleteLeaf ¶
Click to show internal directories.
Click to hide internal directories.