api.cat.health.go 6.0 KB

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