api.xpack.cat.ml_datafeeds.go 7.4 KB

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