/
action.go
44 lines (37 loc) · 827 Bytes
/
action.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package kvstore
func (x *Action) Unwrap() interface{} {
switch action := x.Action.(type) {
case *Action_Set:
return action.Set
case *Action_Delete:
return action.Delete
case *Action_Replace:
return action.Replace
default:
return action
}
}
func (x *Action) IsSet() bool {
return x.GetSet() != nil
}
func (x *Action) IsDelete() bool {
return x.GetDelete() != nil
}
func (x *Action) IsReplace() bool {
return x.GetReplace() != nil
}
func NewSetAction(key string, value *Value) *Action {
return &Action{
Action: &Action_Set{Set: &Set{Key: key, Value: value}},
}
}
func NewDeleteAction(key string) *Action {
return &Action{
Action: &Action_Delete{Delete: &Delete{Key: key}},
}
}
func NewReplaceAction(new *Map) *Action {
return &Action{
Action: &Action_Replace{Replace: &Replace{New: new}},
}
}