1 Star 2 Fork 0

bison-fork/etcd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
event.go 1.67 KB
一键复制 编辑 原始数据 按行查看 历史
Xiang Li 提交于 2013-11-28 21:34 . refactor change node_repr to node_extern
package store
const (
Get = "get"
Create = "create"
Set = "set"
Update = "update"
Delete = "delete"
CompareAndSwap = "compareAndSwap"
Expire = "expire"
)
type Event struct {
Action string `json:"action"`
Node *NodeExtern `json:"node,omitempty"`
}
func newEvent(action string, key string, modifiedIndex, createdIndex uint64) *Event {
n := &NodeExtern{
Key: key,
ModifiedIndex: modifiedIndex,
CreatedIndex: createdIndex,
}
return &Event{
Action: action,
Node: n,
}
}
func (e *Event) IsCreated() bool {
if e.Action == Create {
return true
}
if e.Action == Set && e.Node.PrevValue == "" {
return true
}
return false
}
func (e *Event) Index() uint64 {
return e.Node.ModifiedIndex
}
// Converts an event object into a response object.
func (event *Event) Response() interface{} {
if !event.Node.Dir {
response := &Response{
Action: event.Action,
Key: event.Node.Key,
Value: event.Node.Value,
PrevValue: event.Node.PrevValue,
Index: event.Node.ModifiedIndex,
TTL: event.Node.TTL,
Expiration: event.Node.Expiration,
}
if response.Action == Set {
if response.PrevValue == "" {
response.NewKey = true
}
}
if response.Action == CompareAndSwap || response.Action == Create {
response.Action = "testAndSet"
}
return response
} else {
responses := make([]*Response, len(event.Node.Nodes))
for i, node := range event.Node.Nodes {
responses[i] = &Response{
Action: event.Action,
Key: node.Key,
Value: node.Value,
Dir: node.Dir,
Index: node.ModifiedIndex,
}
}
return responses
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/bison-fork/etcd.git
git@gitee.com:bison-fork/etcd.git
bison-fork
etcd
etcd
v0.2.0-rc2

搜索帮助