etcd/store/v2/create_command.go
Brandon Philips 13b6c1e684 chore(*): make everything use goven
for i in github.com/BurntSushi/toml github.com/coreos/go-etcd/etcd github.com/coreos/go-log/log github.com/gorilla/context github.com/rcrowley/go-metrics bitbucket.org/kardianos/osext github.com/coreos/go-systemd/journal github.com/coreos/raft code.google.com/p/goprotobuf/proto ; do goven  -copy -rewrite $i; done
2014-02-01 23:44:18 -08:00

42 lines
822 B
Go

package v2
import (
"time"
"github.com/coreos/etcd/log"
"github.com/coreos/etcd/store"
"github.com/coreos/etcd/third_party/github.com/coreos/raft"
)
func init() {
raft.RegisterCommand(&CreateCommand{})
}
// Create command
type CreateCommand struct {
Key string `json:"key"`
Value string `json:"value"`
ExpireTime time.Time `json:"expireTime"`
Unique bool `json:"unique"`
Dir bool `json:"dir"`
}
// The name of the create command in the log
func (c *CreateCommand) CommandName() string {
return "etcd:create"
}
// Create node
func (c *CreateCommand) Apply(context raft.Context) (interface{}, error) {
s, _ := context.Server().StateMachine().(store.Store)
e, err := s.Create(c.Key, c.Dir, c.Value, c.Unique, c.ExpireTime)
if err != nil {
log.Debug(err)
return nil, err
}
return e, nil
}