forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_command.go
42 lines (33 loc) · 836 Bytes
/
delete_command.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
package v2
import (
"github.com/coreos/etcd/log"
"github.com/coreos/etcd/store"
"github.com/coreos/etcd/third_party/github.com/goraft/raft"
)
func init() {
raft.RegisterCommand(&DeleteCommand{})
}
// The DeleteCommand removes a key from the Store.
type DeleteCommand struct {
Key string `json:"key"`
Recursive bool `json:"recursive"`
Dir bool `json:"dir"`
}
// The name of the delete command in the log
func (c *DeleteCommand) CommandName() string {
return "etcd:delete"
}
// Delete the key
func (c *DeleteCommand) Apply(context raft.Context) (interface{}, error) {
s, _ := context.Server().StateMachine().(store.Store)
if c.Recursive {
// recursive implies dir
c.Dir = true
}
e, err := s.Delete(c.Key, c.Dir, c.Recursive)
if err != nil {
log.Debug(err)
return nil, err
}
return e, nil
}