api.cat.snapshots.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. // Licensed to Elasticsearch B.V. under one or more contributor
  2. // license agreements. See the NOTICE file distributed with
  3. // this work for additional information regarding copyright
  4. // ownership. Elasticsearch B.V. licenses this file to you under
  5. // the Apache License, Version 2.0 (the "License"); you may
  6. // not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing,
  12. // software distributed under the License is distributed on an
  13. // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. // KIND, either express or implied. See the License for the
  15. // specific language governing permissions and limitations
  16. // under the License.
  17. //
  18. // Code generated from specification version 7.17.10: DO NOT EDIT
  19. package esapi
  20. import (
  21. "context"
  22. "net/http"
  23. "strconv"
  24. "strings"
  25. "time"
  26. )
  27. func newCatSnapshotsFunc(t Transport) CatSnapshots {
  28. return func(o ...func(*CatSnapshotsRequest)) (*Response, error) {
  29. var r = CatSnapshotsRequest{}
  30. for _, f := range o {
  31. f(&r)
  32. }
  33. return r.Do(r.ctx, t)
  34. }
  35. }
  36. // ----- API Definition -------------------------------------------------------
  37. // CatSnapshots returns all snapshots in a specific repository.
  38. //
  39. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-snapshots.html.
  40. type CatSnapshots func(o ...func(*CatSnapshotsRequest)) (*Response, error)
  41. // CatSnapshotsRequest configures the Cat Snapshots API request.
  42. type CatSnapshotsRequest struct {
  43. Repository []string
  44. Format string
  45. H []string
  46. Help *bool
  47. IgnoreUnavailable *bool
  48. MasterTimeout time.Duration
  49. S []string
  50. Time string
  51. V *bool
  52. Pretty bool
  53. Human bool
  54. ErrorTrace bool
  55. FilterPath []string
  56. Header http.Header
  57. ctx context.Context
  58. }
  59. // Do executes the request and returns response or error.
  60. func (r CatSnapshotsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  61. var (
  62. method string
  63. path strings.Builder
  64. params map[string]string
  65. )
  66. method = "GET"
  67. path.Grow(1 + len("_cat") + 1 + len("snapshots") + 1 + len(strings.Join(r.Repository, ",")))
  68. path.WriteString("/")
  69. path.WriteString("_cat")
  70. path.WriteString("/")
  71. path.WriteString("snapshots")
  72. if len(r.Repository) > 0 {
  73. path.WriteString("/")
  74. path.WriteString(strings.Join(r.Repository, ","))
  75. }
  76. params = make(map[string]string)
  77. if r.Format != "" {
  78. params["format"] = r.Format
  79. }
  80. if len(r.H) > 0 {
  81. params["h"] = strings.Join(r.H, ",")
  82. }
  83. if r.Help != nil {
  84. params["help"] = strconv.FormatBool(*r.Help)
  85. }
  86. if r.IgnoreUnavailable != nil {
  87. params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable)
  88. }
  89. if r.MasterTimeout != 0 {
  90. params["master_timeout"] = formatDuration(r.MasterTimeout)
  91. }
  92. if len(r.S) > 0 {
  93. params["s"] = strings.Join(r.S, ",")
  94. }
  95. if r.Time != "" {
  96. params["time"] = r.Time
  97. }
  98. if r.V != nil {
  99. params["v"] = strconv.FormatBool(*r.V)
  100. }
  101. if r.Pretty {
  102. params["pretty"] = "true"
  103. }
  104. if r.Human {
  105. params["human"] = "true"
  106. }
  107. if r.ErrorTrace {
  108. params["error_trace"] = "true"
  109. }
  110. if len(r.FilterPath) > 0 {
  111. params["filter_path"] = strings.Join(r.FilterPath, ",")
  112. }
  113. req, err := newRequest(method, path.String(), nil)
  114. if err != nil {
  115. return nil, err
  116. }
  117. if len(params) > 0 {
  118. q := req.URL.Query()
  119. for k, v := range params {
  120. q.Set(k, v)
  121. }
  122. req.URL.RawQuery = q.Encode()
  123. }
  124. if len(r.Header) > 0 {
  125. if len(req.Header) == 0 {
  126. req.Header = r.Header
  127. } else {
  128. for k, vv := range r.Header {
  129. for _, v := range vv {
  130. req.Header.Add(k, v)
  131. }
  132. }
  133. }
  134. }
  135. if ctx != nil {
  136. req = req.WithContext(ctx)
  137. }
  138. res, err := transport.Perform(req)
  139. if err != nil {
  140. return nil, err
  141. }
  142. response := Response{
  143. StatusCode: res.StatusCode,
  144. Body: res.Body,
  145. Header: res.Header,
  146. }
  147. return &response, nil
  148. }
  149. // WithContext sets the request context.
  150. func (f CatSnapshots) WithContext(v context.Context) func(*CatSnapshotsRequest) {
  151. return func(r *CatSnapshotsRequest) {
  152. r.ctx = v
  153. }
  154. }
  155. // WithRepository - name of repository from which to fetch the snapshot information.
  156. func (f CatSnapshots) WithRepository(v ...string) func(*CatSnapshotsRequest) {
  157. return func(r *CatSnapshotsRequest) {
  158. r.Repository = v
  159. }
  160. }
  161. // WithFormat - a short version of the accept header, e.g. json, yaml.
  162. func (f CatSnapshots) WithFormat(v string) func(*CatSnapshotsRequest) {
  163. return func(r *CatSnapshotsRequest) {
  164. r.Format = v
  165. }
  166. }
  167. // WithH - comma-separated list of column names to display.
  168. func (f CatSnapshots) WithH(v ...string) func(*CatSnapshotsRequest) {
  169. return func(r *CatSnapshotsRequest) {
  170. r.H = v
  171. }
  172. }
  173. // WithHelp - return help information.
  174. func (f CatSnapshots) WithHelp(v bool) func(*CatSnapshotsRequest) {
  175. return func(r *CatSnapshotsRequest) {
  176. r.Help = &v
  177. }
  178. }
  179. // WithIgnoreUnavailable - set to true to ignore unavailable snapshots.
  180. func (f CatSnapshots) WithIgnoreUnavailable(v bool) func(*CatSnapshotsRequest) {
  181. return func(r *CatSnapshotsRequest) {
  182. r.IgnoreUnavailable = &v
  183. }
  184. }
  185. // WithMasterTimeout - explicit operation timeout for connection to master node.
  186. func (f CatSnapshots) WithMasterTimeout(v time.Duration) func(*CatSnapshotsRequest) {
  187. return func(r *CatSnapshotsRequest) {
  188. r.MasterTimeout = v
  189. }
  190. }
  191. // WithS - comma-separated list of column names or column aliases to sort by.
  192. func (f CatSnapshots) WithS(v ...string) func(*CatSnapshotsRequest) {
  193. return func(r *CatSnapshotsRequest) {
  194. r.S = v
  195. }
  196. }
  197. // WithTime - the unit in which to display time values.
  198. func (f CatSnapshots) WithTime(v string) func(*CatSnapshotsRequest) {
  199. return func(r *CatSnapshotsRequest) {
  200. r.Time = v
  201. }
  202. }
  203. // WithV - verbose mode. display column headers.
  204. func (f CatSnapshots) WithV(v bool) func(*CatSnapshotsRequest) {
  205. return func(r *CatSnapshotsRequest) {
  206. r.V = &v
  207. }
  208. }
  209. // WithPretty makes the response body pretty-printed.
  210. func (f CatSnapshots) WithPretty() func(*CatSnapshotsRequest) {
  211. return func(r *CatSnapshotsRequest) {
  212. r.Pretty = true
  213. }
  214. }
  215. // WithHuman makes statistical values human-readable.
  216. func (f CatSnapshots) WithHuman() func(*CatSnapshotsRequest) {
  217. return func(r *CatSnapshotsRequest) {
  218. r.Human = true
  219. }
  220. }
  221. // WithErrorTrace includes the stack trace for errors in the response body.
  222. func (f CatSnapshots) WithErrorTrace() func(*CatSnapshotsRequest) {
  223. return func(r *CatSnapshotsRequest) {
  224. r.ErrorTrace = true
  225. }
  226. }
  227. // WithFilterPath filters the properties of the response body.
  228. func (f CatSnapshots) WithFilterPath(v ...string) func(*CatSnapshotsRequest) {
  229. return func(r *CatSnapshotsRequest) {
  230. r.FilterPath = v
  231. }
  232. }
  233. // WithHeader adds the headers to the HTTP request.
  234. func (f CatSnapshots) WithHeader(h map[string]string) func(*CatSnapshotsRequest) {
  235. return func(r *CatSnapshotsRequest) {
  236. if r.Header == nil {
  237. r.Header = make(http.Header)
  238. }
  239. for k, v := range h {
  240. r.Header.Add(k, v)
  241. }
  242. }
  243. }
  244. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  245. func (f CatSnapshots) WithOpaqueID(s string) func(*CatSnapshotsRequest) {
  246. return func(r *CatSnapshotsRequest) {
  247. if r.Header == nil {
  248. r.Header = make(http.Header)
  249. }
  250. r.Header.Set("X-Opaque-Id", s)
  251. }
  252. }