api.cat.aliases.go 6.7 KB

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