api.cat.recovery.go 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. )
  26. func newCatRecoveryFunc(t Transport) CatRecovery {
  27. return func(o ...func(*CatRecoveryRequest)) (*Response, error) {
  28. var r = CatRecoveryRequest{}
  29. for _, f := range o {
  30. f(&r)
  31. }
  32. return r.Do(r.ctx, t)
  33. }
  34. }
  35. // ----- API Definition -------------------------------------------------------
  36. // CatRecovery returns information about index shard recoveries, both on-going completed.
  37. //
  38. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-recovery.html.
  39. type CatRecovery func(o ...func(*CatRecoveryRequest)) (*Response, error)
  40. // CatRecoveryRequest configures the Cat Recovery API request.
  41. type CatRecoveryRequest struct {
  42. Index []string
  43. ActiveOnly *bool
  44. Bytes string
  45. Detailed *bool
  46. Format string
  47. H []string
  48. Help *bool
  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 CatRecoveryRequest) 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("recovery") + 1 + len(strings.Join(r.Index, ",")))
  68. path.WriteString("/")
  69. path.WriteString("_cat")
  70. path.WriteString("/")
  71. path.WriteString("recovery")
  72. if len(r.Index) > 0 {
  73. path.WriteString("/")
  74. path.WriteString(strings.Join(r.Index, ","))
  75. }
  76. params = make(map[string]string)
  77. if r.ActiveOnly != nil {
  78. params["active_only"] = strconv.FormatBool(*r.ActiveOnly)
  79. }
  80. if r.Bytes != "" {
  81. params["bytes"] = r.Bytes
  82. }
  83. if r.Detailed != nil {
  84. params["detailed"] = strconv.FormatBool(*r.Detailed)
  85. }
  86. if r.Format != "" {
  87. params["format"] = r.Format
  88. }
  89. if len(r.H) > 0 {
  90. params["h"] = strings.Join(r.H, ",")
  91. }
  92. if r.Help != nil {
  93. params["help"] = strconv.FormatBool(*r.Help)
  94. }
  95. if len(r.Index) > 0 {
  96. params["index"] = strings.Join(r.Index, ",")
  97. }
  98. if len(r.S) > 0 {
  99. params["s"] = strings.Join(r.S, ",")
  100. }
  101. if r.Time != "" {
  102. params["time"] = r.Time
  103. }
  104. if r.V != nil {
  105. params["v"] = strconv.FormatBool(*r.V)
  106. }
  107. if r.Pretty {
  108. params["pretty"] = "true"
  109. }
  110. if r.Human {
  111. params["human"] = "true"
  112. }
  113. if r.ErrorTrace {
  114. params["error_trace"] = "true"
  115. }
  116. if len(r.FilterPath) > 0 {
  117. params["filter_path"] = strings.Join(r.FilterPath, ",")
  118. }
  119. req, err := newRequest(method, path.String(), nil)
  120. if err != nil {
  121. return nil, err
  122. }
  123. if len(params) > 0 {
  124. q := req.URL.Query()
  125. for k, v := range params {
  126. q.Set(k, v)
  127. }
  128. req.URL.RawQuery = q.Encode()
  129. }
  130. if len(r.Header) > 0 {
  131. if len(req.Header) == 0 {
  132. req.Header = r.Header
  133. } else {
  134. for k, vv := range r.Header {
  135. for _, v := range vv {
  136. req.Header.Add(k, v)
  137. }
  138. }
  139. }
  140. }
  141. if ctx != nil {
  142. req = req.WithContext(ctx)
  143. }
  144. res, err := transport.Perform(req)
  145. if err != nil {
  146. return nil, err
  147. }
  148. response := Response{
  149. StatusCode: res.StatusCode,
  150. Body: res.Body,
  151. Header: res.Header,
  152. }
  153. return &response, nil
  154. }
  155. // WithContext sets the request context.
  156. func (f CatRecovery) WithContext(v context.Context) func(*CatRecoveryRequest) {
  157. return func(r *CatRecoveryRequest) {
  158. r.ctx = v
  159. }
  160. }
  161. // WithIndex - comma-separated list or wildcard expression of index names to limit the returned information.
  162. func (f CatRecovery) WithIndex(v ...string) func(*CatRecoveryRequest) {
  163. return func(r *CatRecoveryRequest) {
  164. r.Index = v
  165. }
  166. }
  167. // WithActiveOnly - if `true`, the response only includes ongoing shard recoveries.
  168. func (f CatRecovery) WithActiveOnly(v bool) func(*CatRecoveryRequest) {
  169. return func(r *CatRecoveryRequest) {
  170. r.ActiveOnly = &v
  171. }
  172. }
  173. // WithBytes - the unit in which to display byte values.
  174. func (f CatRecovery) WithBytes(v string) func(*CatRecoveryRequest) {
  175. return func(r *CatRecoveryRequest) {
  176. r.Bytes = v
  177. }
  178. }
  179. // WithDetailed - if `true`, the response includes detailed information about shard recoveries.
  180. func (f CatRecovery) WithDetailed(v bool) func(*CatRecoveryRequest) {
  181. return func(r *CatRecoveryRequest) {
  182. r.Detailed = &v
  183. }
  184. }
  185. // WithFormat - a short version of the accept header, e.g. json, yaml.
  186. func (f CatRecovery) WithFormat(v string) func(*CatRecoveryRequest) {
  187. return func(r *CatRecoveryRequest) {
  188. r.Format = v
  189. }
  190. }
  191. // WithH - comma-separated list of column names to display.
  192. func (f CatRecovery) WithH(v ...string) func(*CatRecoveryRequest) {
  193. return func(r *CatRecoveryRequest) {
  194. r.H = v
  195. }
  196. }
  197. // WithHelp - return help information.
  198. func (f CatRecovery) WithHelp(v bool) func(*CatRecoveryRequest) {
  199. return func(r *CatRecoveryRequest) {
  200. r.Help = &v
  201. }
  202. }
  203. // WithS - comma-separated list of column names or column aliases to sort by.
  204. func (f CatRecovery) WithS(v ...string) func(*CatRecoveryRequest) {
  205. return func(r *CatRecoveryRequest) {
  206. r.S = v
  207. }
  208. }
  209. // WithTime - the unit in which to display time values.
  210. func (f CatRecovery) WithTime(v string) func(*CatRecoveryRequest) {
  211. return func(r *CatRecoveryRequest) {
  212. r.Time = v
  213. }
  214. }
  215. // WithV - verbose mode. display column headers.
  216. func (f CatRecovery) WithV(v bool) func(*CatRecoveryRequest) {
  217. return func(r *CatRecoveryRequest) {
  218. r.V = &v
  219. }
  220. }
  221. // WithPretty makes the response body pretty-printed.
  222. func (f CatRecovery) WithPretty() func(*CatRecoveryRequest) {
  223. return func(r *CatRecoveryRequest) {
  224. r.Pretty = true
  225. }
  226. }
  227. // WithHuman makes statistical values human-readable.
  228. func (f CatRecovery) WithHuman() func(*CatRecoveryRequest) {
  229. return func(r *CatRecoveryRequest) {
  230. r.Human = true
  231. }
  232. }
  233. // WithErrorTrace includes the stack trace for errors in the response body.
  234. func (f CatRecovery) WithErrorTrace() func(*CatRecoveryRequest) {
  235. return func(r *CatRecoveryRequest) {
  236. r.ErrorTrace = true
  237. }
  238. }
  239. // WithFilterPath filters the properties of the response body.
  240. func (f CatRecovery) WithFilterPath(v ...string) func(*CatRecoveryRequest) {
  241. return func(r *CatRecoveryRequest) {
  242. r.FilterPath = v
  243. }
  244. }
  245. // WithHeader adds the headers to the HTTP request.
  246. func (f CatRecovery) WithHeader(h map[string]string) func(*CatRecoveryRequest) {
  247. return func(r *CatRecoveryRequest) {
  248. if r.Header == nil {
  249. r.Header = make(http.Header)
  250. }
  251. for k, v := range h {
  252. r.Header.Add(k, v)
  253. }
  254. }
  255. }
  256. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  257. func (f CatRecovery) WithOpaqueID(s string) func(*CatRecoveryRequest) {
  258. return func(r *CatRecoveryRequest) {
  259. if r.Header == nil {
  260. r.Header = make(http.Header)
  261. }
  262. r.Header.Set("X-Opaque-Id", s)
  263. }
  264. }