File: delete.go

package info (click to toggle)
golang-etcd 0.2.0~rc1%2Bgit20140717-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-backports, jessie-kfreebsd
  • size: 188 kB
  • ctags: 165
  • sloc: makefile: 5
file content (40 lines) | stat: -rw-r--r-- 962 bytes parent folder | download | duplicates (3)
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
package etcd

// Delete deletes the given key.
//
// When recursive set to false, if the key points to a
// directory the method will fail.
//
// When recursive set to true, if the key points to a file,
// the file will be deleted; if the key points to a directory,
// then everything under the directory (including all child directories)
// will be deleted.
func (c *Client) Delete(key string, recursive bool) (*Response, error) {
	raw, err := c.RawDelete(key, recursive, false)

	if err != nil {
		return nil, err
	}

	return raw.Unmarshal()
}

// DeleteDir deletes an empty directory or a key value pair
func (c *Client) DeleteDir(key string) (*Response, error) {
	raw, err := c.RawDelete(key, false, true)

	if err != nil {
		return nil, err
	}

	return raw.Unmarshal()
}

func (c *Client) RawDelete(key string, recursive bool, dir bool) (*RawResponse, error) {
	ops := Options{
		"recursive": recursive,
		"dir":       dir,
	}

	return c.delete(key, ops)
}