github.com/macb/etcd@v0.3.1-0.20140227003422-a60481c6b1a0/store/v2/delete_command.go (about)

     1  package v2
     2  
     3  import (
     4  	"github.com/coreos/etcd/log"
     5  	"github.com/coreos/etcd/store"
     6  	"github.com/coreos/etcd/third_party/github.com/coreos/raft"
     7  )
     8  
     9  func init() {
    10  	raft.RegisterCommand(&DeleteCommand{})
    11  }
    12  
    13  // The DeleteCommand removes a key from the Store.
    14  type DeleteCommand struct {
    15  	Key		string	`json:"key"`
    16  	Recursive	bool	`json:"recursive"`
    17  	Dir		bool	`json:"dir"`
    18  }
    19  
    20  // The name of the delete command in the log
    21  func (c *DeleteCommand) CommandName() string {
    22  	return "etcd:delete"
    23  }
    24  
    25  // Delete the key
    26  func (c *DeleteCommand) Apply(context raft.Context) (interface{}, error) {
    27  	s, _ := context.Server().StateMachine().(store.Store)
    28  
    29  	if c.Recursive {
    30  		// recursive implies dir
    31  		c.Dir = true
    32  	}
    33  
    34  	e, err := s.Delete(c.Key, c.Dir, c.Recursive)
    35  
    36  	if err != nil {
    37  		log.Debug(err)
    38  		return nil, err
    39  	}
    40  
    41  	return e, nil
    42  }