package etcd
import "github.com/coreos/go-etcd/etcd"
Index ¶
- Constants
- Variables
- func CloseDebug()
- func OpenDebug()
- func SetCurlChan(c chan string)
- type Client
- func NewClient(machines []string) *Client
- func NewClientFile(fpath string) (*Client, error)
- func NewClientReader(reader io.Reader) (*Client, error)
- func (c *Client) AddChild(key string, value string, ttl uint64) (*Response, error)
- func (c *Client) AddChildDir(key string, ttl uint64) (*Response, error)
- func (c *Client) CompareAndSwap(key string, value string, ttl uint64, prevValue string, prevIndex uint64) (*Response, error)
- func (c *Client) Create(key string, value string, ttl uint64) (*Response, error)
- func (c *Client) CreateDir(key string, ttl uint64) (*Response, error)
- func (c *Client) Delete(key string) (*Response, error)
- func (c *Client) DeleteAll(key string) (*Response, error)
- func (c *Client) Get(key string, sort bool) (*Response, error)
- func (c *Client) GetAll(key string, sort bool) (*Response, error)
- func (c *Client) GetCluster() []string
- func (c *Client) MarshalJSON() ([]byte, error)
- func (c *Client) Set(key string, value string, ttl uint64) (*Response, error)
- func (c *Client) SetCertAndKey(cert string, key string) error
- func (c *Client) SetCluster(machines []string) bool
- func (c *Client) SetConsistency(consistency string) error
- func (c *Client) SetDir(key string, ttl uint64) (*Response, error)
- func (c *Client) SetPersistence(writer io.Writer)
- func (c *Client) SetScheme(scheme int) error
- func (c *Client) SyncCluster() bool
- func (c *Client) UnmarshalJSON(b []byte) error
- func (c *Client) Update(key string, value string, ttl uint64) (*Response, error)
- func (c *Client) UpdateDir(key string, ttl uint64) (*Response, error)
- func (c *Client) Watch(key string, waitIndex uint64, receiver chan *Response, stop chan bool) (*Response, error)
- func (c *Client) WatchAll(prefix string, waitIndex uint64, receiver chan *Response, stop chan bool) (*Response, error)
- type Cluster
- type Config
- type EtcdError
- type KeyValuePair
- type Response
Constants ¶
const ( HTTP = iota HTTPS )
const ( // Using strings rather than iota because the consistency level // could be persisted to disk, so it'd be better to use // human-readable values. STRONG_CONSISTENCY = "STRONG" WEAK_CONSISTENCY = "WEAK" )
See SetConsistency for how to use these constants.
Variables ¶
var ( VALID_GET_OPTIONS = validOptions{ "recursive": reflect.Bool, "consistent": reflect.Bool, "sorted": reflect.Bool, "wait": reflect.Bool, "waitIndex": reflect.Uint64, } VALID_PUT_OPTIONS = validOptions{ "prevValue": reflect.String, "prevIndex": reflect.Uint64, "prevExist": reflect.Bool, } VALID_POST_OPTIONS = validOptions{} VALID_DELETE_OPTIONS = validOptions{ "recursive": reflect.Bool, } )
Valid options for GET, PUT, POST, DELETE Using CAPITALIZED_UNDERSCORE to emphasize that these values are meant to be used as constants.
Errors introduced by the Watch command.
Functions ¶
func CloseDebug ¶
func CloseDebug()
func OpenDebug ¶
func OpenDebug()
func SetCurlChan ¶
func SetCurlChan(c chan string)
SetCurlChan sets a channel to which cURL commands which can be used to re-produce requests are sent. This is useful for debugging.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
NewClient create a basic client that is configured to be used with the given machine list.
func NewClientFile ¶
NewClientFile creates a client from a given file path. The given file is expected to use the JSON format.
func NewClientReader ¶
NewClientReader creates a Client configured from a given reader. The config is expected to use the JSON format.
func (*Client) AddChild ¶
Add a new file with a random etcd-generated key under the given path.
func (*Client) AddChildDir ¶
Add a new directory with a random etcd-generated key under the given path.
func (*Client) CompareAndSwap ¶
func (c *Client) CompareAndSwap(key string, value string, ttl uint64, prevValue string, prevIndex uint64) (*Response, error)
func (*Client) Create ¶
Create creates a file with the given value under the given key. It succeeds only if the given key does not yet exist.
func (*Client) CreateDir ¶
UpdateDir creates a directory under the given key. It succeeds only if the given key does not yet exist.
func (*Client) Delete ¶
Delete deletes the given key. If the key points to a directory, the method will fail.
func (*Client) DeleteAll ¶
DeleteAll deletes everything under the given key. If the key points to a file, the file will be deleted. If the key points to a directory, then everything under the directory, include all child directories, will be deleted.
func (*Client) Get ¶
Get gets the file or directory associated with the given key. If the key points to a directory, files and directories under it will be returned in sorted or unsorted order, depending on the sort flag. Note that contents under child directories will not be returned. To get those contents, use GetAll.
func (*Client) GetAll ¶
GetDir gets the all contents under the given key. If the key points to a file, the file is returned. If the key points to a directory, everything under it is returnd, including all contents under all child directories.
func (*Client) GetCluster ¶
func (*Client) MarshalJSON ¶
MarshalJSON implements the Marshaller interface as defined by the standard JSON package.
func (*Client) Set ¶
Set sets the given key to the given value.
func (*Client) SetCertAndKey ¶
func (*Client) SetCluster ¶
SetCluster updates config using the given machine list.
func (*Client) SetConsistency ¶
SetConsistency changes the consistency level of the client.
When consistency is set to STRONG_CONSISTENCY, all requests, including GET, are sent to the leader. This means that, assuming the absence of leader failures, GET requests are guranteed to see the changes made by previous requests.
When consistency is set to WEAK_CONSISTENCY, other requests are still sent to the leader, but GET requests are sent to a random server from the server pool. This reduces the read load on the leader, but it's not guranteed that the GET requests will see changes made by previous requests (they might have not yet been commited on non-leader servers).
func (*Client) SetDir ¶
SetDir sets the given key to a directory.
func (*Client) SetPersistence ¶
SetPersistence sets a writer to which the config will be written every time it's changed.
func (*Client) SetScheme ¶
func (*Client) SyncCluster ¶
SyncCluster updates config using the internal machine list.
func (*Client) UnmarshalJSON ¶
UnmarshalJSON implements the Unmarshaller interface as defined by the standard JSON package.
func (*Client) Update ¶
Update updates the given key to the given value. It succeeds only if the given key already exists.
func (*Client) UpdateDir ¶
UpdateDir updates the given key to a directory. It succeeds only if the given key already exists.
func (*Client) Watch ¶
func (c *Client) Watch(key string, waitIndex uint64, receiver chan *Response, stop chan bool) (*Response, error)
Watch returns the first change to the given key since the given index. To watch for the latest change, set waitIndex = 0.
If a receiver channel is given, it will be a long-term watch. Watch will block at the channel. And after someone receive the channel, it will go on to watch that prefix. If a stop channel is given, client can close long-term watch using the stop channel
func (*Client) WatchAll ¶
func (c *Client) WatchAll(prefix string, waitIndex uint64, receiver chan *Response, stop chan bool) (*Response, error)
WatchAll returns the first change under the given prefix since the given index. To watch for the latest change, set waitIndex = 0.
If the prefix points to a directory, any change under it, including all child directories, will be returned.
If a receiver channel is given, it will be a long-term watch. Watch will block at the channel. And after someone receive the channel, it will go on to watch that prefix. If a stop channel is given, client can close long-term watch using the stop channel
type Cluster ¶
type Config ¶
type Config struct { CertFile string `json:"certFile"` KeyFile string `json:"keyFile"` Scheme string `json:"scheme"` Timeout time.Duration `json:"timeout"` Consistency string `json: "consistency"` }
type EtcdError ¶
type EtcdError struct { ErrorCode int `json:"errorCode"` Message string `json:"message"` Cause string `json:"cause,omitempty"` }
func (EtcdError) Error ¶
type KeyValuePair ¶
type KeyValuePair struct { Key string `json:"key, omitempty"` Value string `json:"value,omitempty"` Dir bool `json:"dir,omitempty"` KVPairs kvPairs `json:"kvs,omitempty"` }
When user list a directory, we add all the node into key-value pair slice
type Response ¶
type Response struct { Action string `json:"action"` Key string `json:"key"` Dir bool `json:"dir,omitempty"` PrevValue string `json:"prevValue,omitempty"` Value string `json:"value,omitempty"` Kvs kvPairs `json:"kvs,omitempty"` // If the key did not exist before the action, // this field should be set to true NewKey bool `json:"newKey,omitempty"` Expiration *time.Time `json:"expiration,omitempty"` // Time to live in second TTL int64 `json:"ttl,omitempty"` // The command index of the raft machine when the command is executed Index uint64 `json:"index"` }
The response object from the server.
Source Files ¶
add_child.go client.go compare_and_swap.go debug.go delete.go error.go get.go requests.go response.go set_update_create.go utils.go version.go watch.go
- Version
- v0.2.0-rc1
- Published
- Nov 14, 2013
- Platform
- js/wasm
- Imports
- 16 packages
- Last checked
- 2 hours ago –
Tools for package owners.