get_command.go 744 B

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