op.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Copyright 2016 CoreOS, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package clientv3
  15. type opType int
  16. const (
  17. // A default Op has opType 0, which is invalid.
  18. tRange opType = iota + 1
  19. tPut
  20. tDeleteRange
  21. )
  22. // Op represents an Operation that kv can execute.
  23. type Op struct {
  24. t opType
  25. key []byte
  26. end []byte
  27. // for range
  28. limit int64
  29. rev int64
  30. sort *SortOption
  31. }
  32. func OpRange(key, end string, limit, rev int64, sort *SortOption) Op {
  33. return Op{
  34. t: tRange,
  35. key: []byte(key),
  36. end: []byte(end),
  37. limit: limit,
  38. rev: rev,
  39. sort: sort,
  40. }
  41. }
  42. func OpGet(key string, rev int64) Op {
  43. return Op{
  44. t: tRange,
  45. key: []byte(key),
  46. rev: rev,
  47. }
  48. }
  49. func OpDeleteRange(key, end string) Op {
  50. return Op{
  51. t: tDeleteRange,
  52. key: []byte(key),
  53. end: []byte(end),
  54. }
  55. }
  56. func OpDelete(key string) Op {
  57. return Op{
  58. t: tDeleteRange,
  59. key: []byte(key),
  60. }
  61. }