mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package client
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
ErrUnavailable = errors.New("client: no available etcd endpoints")
|
|
ErrNoLeader = errors.New("client: no leader")
|
|
ErrKeyNoExist = errors.New("client: key does not exist")
|
|
ErrKeyExists = errors.New("client: key already exists")
|
|
)
|
|
|
|
type Client interface {
|
|
Create(key, value string, ttl time.Duration) (*Response, error)
|
|
Get(key string) (*Response, error)
|
|
Watch(key string, idx uint64) Watcher
|
|
RecursiveWatch(key string, idx uint64) Watcher
|
|
}
|
|
|
|
type Watcher interface {
|
|
Next() (*Response, error)
|
|
}
|
|
|
|
type Response struct {
|
|
Action string `json:"action"`
|
|
Node *Node `json:"node"`
|
|
PrevNode *Node `json:"prevNode"`
|
|
}
|
|
|
|
type Nodes []*Node
|
|
type Node struct {
|
|
Key string `json:"key"`
|
|
Value string `json:"value"`
|
|
Nodes Nodes `json:"nodes"`
|
|
ModifiedIndex uint64 `json:"modifiedIndex"`
|
|
CreatedIndex uint64 `json:"createdIndex"`
|
|
}
|
|
|
|
func (n *Node) String() string {
|
|
return fmt.Sprintf("{Key: %s, CreatedIndex: %d, ModifiedIndex: %d}", n.Key, n.CreatedIndex, n.ModifiedIndex)
|
|
}
|