api.cat.repositories.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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 newCatRepositoriesFunc(t Transport) CatRepositories {
  28. return func(o ...func(*CatRepositoriesRequest)) (*Response, error) {
  29. var r = CatRepositoriesRequest{}
  30. for _, f := range o {
  31. f(&r)
  32. }
  33. return r.Do(r.ctx, t)
  34. }
  35. }
  36. // ----- API Definition -------------------------------------------------------
  37. // CatRepositories returns information about snapshot repositories registered in the cluster.
  38. //
  39. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/cat-repositories.html.
  40. type CatRepositories func(o ...func(*CatRepositoriesRequest)) (*Response, error)
  41. // CatRepositoriesRequest configures the Cat Repositories API request.
  42. type CatRepositoriesRequest struct {
  43. Format string
  44. H []string
  45. Help *bool
  46. Local *bool
  47. MasterTimeout time.Duration
  48. S []string
  49. V *bool
  50. Pretty bool
  51. Human bool
  52. ErrorTrace bool
  53. FilterPath []string
  54. Header http.Header
  55. ctx context.Context
  56. }
  57. // Do executes the request and returns response or error.
  58. func (r CatRepositoriesRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  59. var (
  60. method string
  61. path strings.Builder
  62. params map[string]string
  63. )
  64. method = "GET"
  65. path.Grow(len("/_cat/repositories"))
  66. path.WriteString("/_cat/repositories")
  67. params = make(map[string]string)
  68. if r.Format != "" {
  69. params["format"] = r.Format
  70. }
  71. if len(r.H) > 0 {
  72. params["h"] = strings.Join(r.H, ",")
  73. }
  74. if r.Help != nil {
  75. params["help"] = strconv.FormatBool(*r.Help)
  76. }
  77. if r.Local != nil {
  78. params["local"] = strconv.FormatBool(*r.Local)
  79. }
  80. if r.MasterTimeout != 0 {
  81. params["master_timeout"] = formatDuration(r.MasterTimeout)
  82. }
  83. if len(r.S) > 0 {
  84. params["s"] = strings.Join(r.S, ",")
  85. }
  86. if r.V != nil {
  87. params["v"] = strconv.FormatBool(*r.V)
  88. }
  89. if r.Pretty {
  90. params["pretty"] = "true"
  91. }
  92. if r.Human {
  93. params["human"] = "true"
  94. }
  95. if r.ErrorTrace {
  96. params["error_trace"] = "true"
  97. }
  98. if len(r.FilterPath) > 0 {
  99. params["filter_path"] = strings.Join(r.FilterPath, ",")
  100. }
  101. req, err := newRequest(method, path.String(), nil)
  102. if err != nil {
  103. return nil, err
  104. }
  105. if len(params) > 0 {
  106. q := req.URL.Query()
  107. for k, v := range params {
  108. q.Set(k, v)
  109. }
  110. req.URL.RawQuery = q.Encode()
  111. }
  112. if len(r.Header) > 0 {
  113. if len(req.Header) == 0 {
  114. req.Header = r.Header
  115. } else {
  116. for k, vv := range r.Header {
  117. for _, v := range vv {
  118. req.Header.Add(k, v)
  119. }
  120. }
  121. }
  122. }
  123. if ctx != nil {
  124. req = req.WithContext(ctx)
  125. }
  126. res, err := transport.Perform(req)
  127. if err != nil {
  128. return nil, err
  129. }
  130. response := Response{
  131. StatusCode: res.StatusCode,
  132. Body: res.Body,
  133. Header: res.Header,
  134. }
  135. return &response, nil
  136. }
  137. // WithContext sets the request context.
  138. func (f CatRepositories) WithContext(v context.Context) func(*CatRepositoriesRequest) {
  139. return func(r *CatRepositoriesRequest) {
  140. r.ctx = v
  141. }
  142. }
  143. // WithFormat - a short version of the accept header, e.g. json, yaml.
  144. func (f CatRepositories) WithFormat(v string) func(*CatRepositoriesRequest) {
  145. return func(r *CatRepositoriesRequest) {
  146. r.Format = v
  147. }
  148. }
  149. // WithH - comma-separated list of column names to display.
  150. func (f CatRepositories) WithH(v ...string) func(*CatRepositoriesRequest) {
  151. return func(r *CatRepositoriesRequest) {
  152. r.H = v
  153. }
  154. }
  155. // WithHelp - return help information.
  156. func (f CatRepositories) WithHelp(v bool) func(*CatRepositoriesRequest) {
  157. return func(r *CatRepositoriesRequest) {
  158. r.Help = &v
  159. }
  160. }
  161. // WithLocal - return local information, do not retrieve the state from master node.
  162. func (f CatRepositories) WithLocal(v bool) func(*CatRepositoriesRequest) {
  163. return func(r *CatRepositoriesRequest) {
  164. r.Local = &v
  165. }
  166. }
  167. // WithMasterTimeout - explicit operation timeout for connection to master node.
  168. func (f CatRepositories) WithMasterTimeout(v time.Duration) func(*CatRepositoriesRequest) {
  169. return func(r *CatRepositoriesRequest) {
  170. r.MasterTimeout = v
  171. }
  172. }
  173. // WithS - comma-separated list of column names or column aliases to sort by.
  174. func (f CatRepositories) WithS(v ...string) func(*CatRepositoriesRequest) {
  175. return func(r *CatRepositoriesRequest) {
  176. r.S = v
  177. }
  178. }
  179. // WithV - verbose mode. display column headers.
  180. func (f CatRepositories) WithV(v bool) func(*CatRepositoriesRequest) {
  181. return func(r *CatRepositoriesRequest) {
  182. r.V = &v
  183. }
  184. }
  185. // WithPretty makes the response body pretty-printed.
  186. func (f CatRepositories) WithPretty() func(*CatRepositoriesRequest) {
  187. return func(r *CatRepositoriesRequest) {
  188. r.Pretty = true
  189. }
  190. }
  191. // WithHuman makes statistical values human-readable.
  192. func (f CatRepositories) WithHuman() func(*CatRepositoriesRequest) {
  193. return func(r *CatRepositoriesRequest) {
  194. r.Human = true
  195. }
  196. }
  197. // WithErrorTrace includes the stack trace for errors in the response body.
  198. func (f CatRepositories) WithErrorTrace() func(*CatRepositoriesRequest) {
  199. return func(r *CatRepositoriesRequest) {
  200. r.ErrorTrace = true
  201. }
  202. }
  203. // WithFilterPath filters the properties of the response body.
  204. func (f CatRepositories) WithFilterPath(v ...string) func(*CatRepositoriesRequest) {
  205. return func(r *CatRepositoriesRequest) {
  206. r.FilterPath = v
  207. }
  208. }
  209. // WithHeader adds the headers to the HTTP request.
  210. func (f CatRepositories) WithHeader(h map[string]string) func(*CatRepositoriesRequest) {
  211. return func(r *CatRepositoriesRequest) {
  212. if r.Header == nil {
  213. r.Header = make(http.Header)
  214. }
  215. for k, v := range h {
  216. r.Header.Add(k, v)
  217. }
  218. }
  219. }
  220. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  221. func (f CatRepositories) WithOpaqueID(s string) func(*CatRepositoriesRequest) {
  222. return func(r *CatRepositoriesRequest) {
  223. if r.Header == nil {
  224. r.Header = make(http.Header)
  225. }
  226. r.Header.Set("X-Opaque-Id", s)
  227. }
  228. }