api.cat.shards.go 7.1 KB

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