delete_command.go 727 B

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