13 Star 51 Fork 0

Gitee 极速下载/etcd

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/coreos/etcd
克隆/下载
event.go 1.96 KB
一键复制 编辑 原始数据 按行查看 历史
package store
const (
Get = "get"
Create = "create"
Set = "set"
Update = "update"
Delete = "delete"
CompareAndSwap = "compareAndSwap"
CompareAndDelete = "compareAndDelete"
Expire = "expire"
)
type Event struct {
Action string `json:"action"`
Node *NodeExtern `json:"node,omitempty"`
PrevNode *NodeExtern `json:"prevNode,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.PrevNode == nil {
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(currentIndex uint64) interface{} {
if !event.Node.Dir {
response := &Response{
Action: event.Action,
Key: event.Node.Key,
Value: event.Node.Value,
Index: event.Node.ModifiedIndex,
TTL: event.Node.TTL,
Expiration: event.Node.Expiration,
}
if event.PrevNode != nil {
response.PrevValue = event.PrevNode.Value
}
if currentIndex != 0 {
response.Index = currentIndex
}
if response.Action == Set {
if response.PrevValue == nil {
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,
}
if currentIndex != 0 {
responses[i].Index = currentIndex
}
}
return responses
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/etcd.git
git@gitee.com:mirrors/etcd.git
mirrors
etcd
etcd
v0.4.6

搜索帮助