-
Notifications
You must be signed in to change notification settings - Fork 458
/
Copy pathop.go
91 lines (73 loc) · 3.23 KB
/
op.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package kv
import "github.com/golang/protobuf/proto"
type condition struct {
targetType TargetType
compareType CompareType
key string
value interface{}
}
// NewCondition returns a new Condition
func NewCondition() Condition { return condition{} }
func (c condition) TargetType() TargetType { return c.targetType }
func (c condition) CompareType() CompareType { return c.compareType }
func (c condition) Key() string { return c.key }
func (c condition) Value() interface{} { return c.value }
func (c condition) SetTargetType(t TargetType) Condition { c.targetType = t; return c }
func (c condition) SetCompareType(t CompareType) Condition { c.compareType = t; return c }
func (c condition) SetKey(key string) Condition { c.key = key; return c }
func (c condition) SetValue(value interface{}) Condition { c.value = value; return c }
type opBase struct {
ot OpType
key string
}
// nolint: unparam
func newOpBase(t OpType, key string) opBase { return opBase{ot: t, key: key} }
func (r opBase) Type() OpType { return r.ot }
func (r opBase) Key() string { return r.key }
func (r opBase) SetType(t OpType) Op { r.ot = t; return r }
func (r opBase) SetKey(key string) Op { r.key = key; return r }
// SetOp is a Op with OpType Set
type SetOp struct {
opBase
Value proto.Message
}
// NewSetOp returns a SetOp
func NewSetOp(key string, value proto.Message) SetOp {
return SetOp{opBase: newOpBase(OpSet, key), Value: value}
}
type opResponse struct {
Op
value interface{}
}
// NewOpResponse creates a new OpResponse
func NewOpResponse(op Op) OpResponse {
return opResponse{Op: op}
}
func (r opResponse) Value() interface{} { return r.value }
func (r opResponse) SetValue(v interface{}) OpResponse { r.value = v; return r }
type response struct {
opr []OpResponse
}
// NewResponse creates a new transaction Response
func NewResponse() Response { return response{} }
func (r response) Responses() []OpResponse { return r.opr }
func (r response) SetResponses(oprs []OpResponse) Response { r.opr = oprs; return r }