api.xpack.cat.transforms.go 7.5 KB

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