github.com/ghodss/etcd@v0.3.1-0.20140417172404-cc329bfa55cb/store/v2/create_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(&CreateCommand{}) 13 } 14 15 // Create command 16 type CreateCommand struct { 17 Key string `json:"key"` 18 Value string `json:"value"` 19 ExpireTime time.Time `json:"expireTime"` 20 Unique bool `json:"unique"` 21 Dir bool `json:"dir"` 22 } 23 24 // The name of the create command in the log 25 func (c *CreateCommand) CommandName() string { 26 return "etcd:create" 27 } 28 29 // Create node 30 func (c *CreateCommand) Apply(context raft.Context) (interface{}, error) { 31 s, _ := context.Server().StateMachine().(store.Store) 32 33 e, err := s.Create(c.Key, c.Dir, c.Value, c.Unique, c.ExpireTime) 34 35 if err != nil { 36 log.Debug(err) 37 return nil, err 38 } 39 40 return e, nil 41 }