by.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. package store
  2. import "github.com/docker/swarmkit/api"
  3. // By is an interface type passed to Find methods. Implementations must be
  4. // defined in this package.
  5. type By interface {
  6. // isBy allows this interface to only be satisfied by certain internal
  7. // types.
  8. isBy()
  9. }
  10. type byAll struct{}
  11. func (a byAll) isBy() {
  12. }
  13. // All is an argument that can be passed to find to list all items in the
  14. // set.
  15. var All byAll
  16. type byNamePrefix string
  17. func (b byNamePrefix) isBy() {
  18. }
  19. // ByNamePrefix creates an object to pass to Find to select by query.
  20. func ByNamePrefix(namePrefix string) By {
  21. return byNamePrefix(namePrefix)
  22. }
  23. type byIDPrefix string
  24. func (b byIDPrefix) isBy() {
  25. }
  26. // ByIDPrefix creates an object to pass to Find to select by query.
  27. func ByIDPrefix(idPrefix string) By {
  28. return byIDPrefix(idPrefix)
  29. }
  30. type byName string
  31. func (b byName) isBy() {
  32. }
  33. // ByName creates an object to pass to Find to select by name.
  34. func ByName(name string) By {
  35. return byName(name)
  36. }
  37. type byService string
  38. func (b byService) isBy() {
  39. }
  40. type byRuntime string
  41. func (b byRuntime) isBy() {
  42. }
  43. // ByRuntime creates an object to pass to Find to select by runtime.
  44. func ByRuntime(runtime string) By {
  45. return byRuntime(runtime)
  46. }
  47. // ByServiceID creates an object to pass to Find to select by service.
  48. func ByServiceID(serviceID string) By {
  49. return byService(serviceID)
  50. }
  51. type byNode string
  52. func (b byNode) isBy() {
  53. }
  54. // ByNodeID creates an object to pass to Find to select by node.
  55. func ByNodeID(nodeID string) By {
  56. return byNode(nodeID)
  57. }
  58. type bySlot struct {
  59. serviceID string
  60. slot uint64
  61. }
  62. func (b bySlot) isBy() {
  63. }
  64. // BySlot creates an object to pass to Find to select by slot.
  65. func BySlot(serviceID string, slot uint64) By {
  66. return bySlot{serviceID: serviceID, slot: slot}
  67. }
  68. type byDesiredState api.TaskState
  69. func (b byDesiredState) isBy() {
  70. }
  71. // ByDesiredState creates an object to pass to Find to select by desired state.
  72. func ByDesiredState(state api.TaskState) By {
  73. return byDesiredState(state)
  74. }
  75. type byTaskState api.TaskState
  76. func (b byTaskState) isBy() {
  77. }
  78. // ByTaskState creates an object to pass to Find to select by task state.
  79. func ByTaskState(state api.TaskState) By {
  80. return byTaskState(state)
  81. }
  82. type byRole api.NodeRole
  83. func (b byRole) isBy() {
  84. }
  85. // ByRole creates an object to pass to Find to select by role.
  86. func ByRole(role api.NodeRole) By {
  87. return byRole(role)
  88. }
  89. type byMembership api.NodeSpec_Membership
  90. func (b byMembership) isBy() {
  91. }
  92. // ByMembership creates an object to pass to Find to select by Membership.
  93. func ByMembership(membership api.NodeSpec_Membership) By {
  94. return byMembership(membership)
  95. }
  96. type byReferencedNetworkID string
  97. func (b byReferencedNetworkID) isBy() {
  98. }
  99. // ByReferencedNetworkID creates an object to pass to Find to search for a
  100. // service or task that references a network with the given ID.
  101. func ByReferencedNetworkID(networkID string) By {
  102. return byReferencedNetworkID(networkID)
  103. }
  104. type byReferencedSecretID string
  105. func (b byReferencedSecretID) isBy() {
  106. }
  107. // ByReferencedSecretID creates an object to pass to Find to search for a
  108. // service or task that references a secret with the given ID.
  109. func ByReferencedSecretID(secretID string) By {
  110. return byReferencedSecretID(secretID)
  111. }
  112. type byReferencedConfigID string
  113. func (b byReferencedConfigID) isBy() {
  114. }
  115. // ByReferencedConfigID creates an object to pass to Find to search for a
  116. // service or task that references a config with the given ID.
  117. func ByReferencedConfigID(configID string) By {
  118. return byReferencedConfigID(configID)
  119. }
  120. type byKind string
  121. func (b byKind) isBy() {
  122. }
  123. // ByKind creates an object to pass to Find to search for a Resource of a
  124. // particular kind.
  125. func ByKind(kind string) By {
  126. return byKind(kind)
  127. }
  128. type byCustom struct {
  129. objType string
  130. index string
  131. value string
  132. }
  133. func (b byCustom) isBy() {
  134. }
  135. // ByCustom creates an object to pass to Find to search a custom index.
  136. func ByCustom(objType, index, value string) By {
  137. return byCustom{
  138. objType: objType,
  139. index: index,
  140. value: value,
  141. }
  142. }
  143. type byCustomPrefix struct {
  144. objType string
  145. index string
  146. value string
  147. }
  148. func (b byCustomPrefix) isBy() {
  149. }
  150. // ByCustomPrefix creates an object to pass to Find to search a custom index by
  151. // a value prefix.
  152. func ByCustomPrefix(objType, index, value string) By {
  153. return byCustomPrefix{
  154. objType: objType,
  155. index: index,
  156. value: value,
  157. }
  158. }