github.com/sym3tri/etcd@v0.2.1-0.20140422215517-a563d82f95d6/store/v2/update_command.go (about) 1 package v2 2 3 import ( 4 "time" 5 6 "github.com/coreos/etcd/log" 7 "github.com/coreos/etcd/store" 8 "github.com/coreos/etcd/third_party/github.com/goraft/raft" 9 ) 10 11 func init() { 12 raft.RegisterCommand(&UpdateCommand{}) 13 } 14 15 // Update command 16 type UpdateCommand struct { 17 Key string `json:"key"` 18 Value string `json:"value"` 19 ExpireTime time.Time `json:"expireTime"` 20 } 21 22 // The name of the update command in the log 23 func (c *UpdateCommand) CommandName() string { 24 return "etcd:update" 25 } 26 27 // Create node 28 func (c *UpdateCommand) Apply(context raft.Context) (interface{}, error) { 29 s, _ := context.Server().StateMachine().(store.Store) 30 31 e, err := s.Update(c.Key, c.Value, c.ExpireTime) 32 33 if err != nil { 34 log.Debug(err) 35 return nil, err 36 } 37 38 return e, nil 39 }