|
@@ -1,8 +1,10 @@
|
|
|
package etcd
|
|
package etcd
|
|
|
|
|
|
|
|
-// SetDir sets the given key to a directory.
|
|
|
|
|
-func (c *Client) SetDir(key string, ttl uint64) (*Response, error) {
|
|
|
|
|
- raw, err := c.RawSetDir(key, ttl)
|
|
|
|
|
|
|
+// Set sets the given key to the given value.
|
|
|
|
|
+// It will create a new key value pair or replace the old one.
|
|
|
|
|
+// It will not replace a existing directory.
|
|
|
|
|
+func (c *Client) Set(key string, value string, ttl uint64) (*Response, error) {
|
|
|
|
|
+ raw, err := c.RawSet(key, value, ttl)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
@@ -11,10 +13,11 @@ func (c *Client) SetDir(key string, ttl uint64) (*Response, error) {
|
|
|
return raw.toResponse()
|
|
return raw.toResponse()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// UpdateDir updates the given key to a directory. It succeeds only if the
|
|
|
|
|
-// given key already exists.
|
|
|
|
|
-func (c *Client) UpdateDir(key string, ttl uint64) (*Response, error) {
|
|
|
|
|
- raw, err := c.RawUpdateDir(key, ttl)
|
|
|
|
|
|
|
+// Set sets the given key to a directory.
|
|
|
|
|
+// It will create a new directory or replace the old key value pair by a directory.
|
|
|
|
|
+// It will not replace a existing directory.
|
|
|
|
|
+func (c *Client) SetDir(key string, ttl uint64) (*Response, error) {
|
|
|
|
|
+ raw, err := c.RawSetDir(key, ttl)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
@@ -23,7 +26,7 @@ func (c *Client) UpdateDir(key string, ttl uint64) (*Response, error) {
|
|
|
return raw.toResponse()
|
|
return raw.toResponse()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// UpdateDir creates a directory under the given key. It succeeds only if
|
|
|
|
|
|
|
+// CreateDir creates a directory. It succeeds only if
|
|
|
// the given key does not yet exist.
|
|
// the given key does not yet exist.
|
|
|
func (c *Client) CreateDir(key string, ttl uint64) (*Response, error) {
|
|
func (c *Client) CreateDir(key string, ttl uint64) (*Response, error) {
|
|
|
raw, err := c.RawCreateDir(key, ttl)
|
|
raw, err := c.RawCreateDir(key, ttl)
|
|
@@ -35,9 +38,10 @@ func (c *Client) CreateDir(key string, ttl uint64) (*Response, error) {
|
|
|
return raw.toResponse()
|
|
return raw.toResponse()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Set sets the given key to the given value.
|
|
|
|
|
-func (c *Client) Set(key string, value string, ttl uint64) (*Response, error) {
|
|
|
|
|
- raw, err := c.RawSet(key, value, ttl)
|
|
|
|
|
|
|
+// UpdateDir updates the given directory. It succeeds only if the
|
|
|
|
|
+// given key already exists.
|
|
|
|
|
+func (c *Client) UpdateDir(key string, ttl uint64) (*Response, error) {
|
|
|
|
|
+ raw, err := c.RawUpdateDir(key, ttl)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
@@ -46,10 +50,10 @@ func (c *Client) Set(key string, value string, ttl uint64) (*Response, error) {
|
|
|
return raw.toResponse()
|
|
return raw.toResponse()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Update updates the given key to the given value. It succeeds only if the
|
|
|
|
|
-// given key already exists.
|
|
|
|
|
-func (c *Client) Update(key string, value string, ttl uint64) (*Response, error) {
|
|
|
|
|
- raw, err := c.RawUpdate(key, value, ttl)
|
|
|
|
|
|
|
+// Create creates a file with the given value under the given key. It succeeds
|
|
|
|
|
+// only if the given key does not yet exist.
|
|
|
|
|
+func (c *Client) Create(key string, value string, ttl uint64) (*Response, error) {
|
|
|
|
|
+ raw, err := c.RawCreate(key, value, ttl)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
@@ -58,10 +62,10 @@ func (c *Client) Update(key string, value string, ttl uint64) (*Response, error)
|
|
|
return raw.toResponse()
|
|
return raw.toResponse()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Create creates a file with the given value under the given key. It succeeds
|
|
|
|
|
-// only if the given key does not yet exist.
|
|
|
|
|
-func (c *Client) Create(key string, value string, ttl uint64) (*Response, error) {
|
|
|
|
|
- raw, err := c.RawCreate(key, value, ttl)
|
|
|
|
|
|
|
+// Update updates the given key to the given value. It succeeds only if the
|
|
|
|
|
+// given key already exists.
|
|
|
|
|
+func (c *Client) Update(key string, value string, ttl uint64) (*Response, error) {
|
|
|
|
|
+ raw, err := c.RawUpdate(key, value, ttl)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, err
|
|
return nil, err
|
|
@@ -70,13 +74,10 @@ func (c *Client) Create(key string, value string, ttl uint64) (*Response, error)
|
|
|
return raw.toResponse()
|
|
return raw.toResponse()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (c *Client) RawSetDir(key string, ttl uint64) (*RawResponse, error) {
|
|
|
|
|
- return c.put(key, "", ttl, nil)
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
func (c *Client) RawUpdateDir(key string, ttl uint64) (*RawResponse, error) {
|
|
func (c *Client) RawUpdateDir(key string, ttl uint64) (*RawResponse, error) {
|
|
|
ops := options{
|
|
ops := options{
|
|
|
"prevExist": true,
|
|
"prevExist": true,
|
|
|
|
|
+ "dir": true,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return c.put(key, "", ttl, ops)
|
|
return c.put(key, "", ttl, ops)
|
|
@@ -85,6 +86,7 @@ func (c *Client) RawUpdateDir(key string, ttl uint64) (*RawResponse, error) {
|
|
|
func (c *Client) RawCreateDir(key string, ttl uint64) (*RawResponse, error) {
|
|
func (c *Client) RawCreateDir(key string, ttl uint64) (*RawResponse, error) {
|
|
|
ops := options{
|
|
ops := options{
|
|
|
"prevExist": false,
|
|
"prevExist": false,
|
|
|
|
|
+ "dir": true,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return c.put(key, "", ttl, ops)
|
|
return c.put(key, "", ttl, ops)
|
|
@@ -94,6 +96,14 @@ func (c *Client) RawSet(key string, value string, ttl uint64) (*RawResponse, err
|
|
|
return c.put(key, value, ttl, nil)
|
|
return c.put(key, value, ttl, nil)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func (c *Client) RawSetDir(key string, ttl uint64) (*RawResponse, error) {
|
|
|
|
|
+ ops := options{
|
|
|
|
|
+ "dir": true,
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return c.put(key, "", ttl, ops)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
func (c *Client) RawUpdate(key string, value string, ttl uint64) (*RawResponse, error) {
|
|
func (c *Client) RawUpdate(key string, value string, ttl uint64) (*RawResponse, error) {
|
|
|
ops := options{
|
|
ops := options{
|
|
|
"prevExist": true,
|
|
"prevExist": true,
|