forked from pachyderm/pachyderm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
discovery.go
47 lines (42 loc) · 1.53 KB
/
discovery.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package discovery
import (
"errors"
)
var (
ErrNetwork = errors.New("pachyderm: network failure")
ErrNotFound = errors.New("pachyderm: Not found")
ErrValue = errors.New("pachyderm: Found value instead of directory")
ErrDirectory = errors.New("pachyderm: Found directory instead of value")
ErrExists = errors.New("pachyderm: Key already exists")
ErrPrecondition = errors.New("pachyderm: Precondition not met")
)
type Client interface {
// Close closes the underlying connection
// Errors: ErrNetwork
Close() error
// Get gets the value of a key
// Errors: ErrNetwork, ErrNotFound, ErrDirectory
Get(key string) (string, error)
// GetAll returns all of the keys in a directory and its subdirectories as
// a map from absolute keys to values.
// Errors: ErrNetwork
GetAll(key string) (map[string]string, error)
// Set sets the value for a key
// Errors: ErrNetwork, ErrDirectory
Set(key string, value string) error
// Delete deletes a key.
// Errors: ErrNetwork, ErrNotFound, ErrDirectory
Delete(key string) error
// Create is like Set but only succeeds if the key doesn't already exist
// Errors: ErrNetwork, ErrExists
Create(key string, value string) error
// CheckAndSet is like Set but only succeeds if the key is already set to oldValue
// Errors: ErrNetwork, ErrNotFound, ErrDirectory, ErrPrecondition
CheckAndSet(key string, value string, oldValue string) error
}
func NewEtcdClient(addresses ...string) Client {
return newEtcdClient(addresses...)
}
func NewMockClient() Client {
return newMockClient()
}