delete_command.go 677 B

1234567891011121314151617181920212223242526272829303132
  1. package command
  2. import (
  3. "github.com/coreos/etcd/log"
  4. "github.com/coreos/etcd/store"
  5. "github.com/coreos/go-raft"
  6. )
  7. // The DeleteCommand removes a key from the Store.
  8. type DeleteCommand struct {
  9. Key string `json:"key"`
  10. Recursive bool `json:"recursive"`
  11. }
  12. // The name of the delete command in the log
  13. func (c *DeleteCommand) CommandName() string {
  14. return "etcd:delete"
  15. }
  16. // Delete the key
  17. func (c *DeleteCommand) Apply(server *raft.Server) (interface{}, error) {
  18. s, _ := server.StateMachine().(*store.Store)
  19. e, err := s.Delete(c.Key, c.Recursive, server.CommitIndex(), server.Term())
  20. if err != nil {
  21. log.Debug(err)
  22. return nil, err
  23. }
  24. return e, nil
  25. }