api.indices.get_template.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 newIndicesGetTemplateFunc(t Transport) IndicesGetTemplate {
  28. return func(o ...func(*IndicesGetTemplateRequest)) (*Response, error) {
  29. var r = IndicesGetTemplateRequest{}
  30. for _, f := range o {
  31. f(&r)
  32. }
  33. return r.Do(r.ctx, t)
  34. }
  35. }
  36. // ----- API Definition -------------------------------------------------------
  37. // IndicesGetTemplate returns an index template.
  38. //
  39. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html.
  40. type IndicesGetTemplate func(o ...func(*IndicesGetTemplateRequest)) (*Response, error)
  41. // IndicesGetTemplateRequest configures the Indices Get Template API request.
  42. type IndicesGetTemplateRequest struct {
  43. Name []string
  44. FlatSettings *bool
  45. IncludeTypeName *bool
  46. Local *bool
  47. MasterTimeout time.Duration
  48. Pretty bool
  49. Human bool
  50. ErrorTrace bool
  51. FilterPath []string
  52. Header http.Header
  53. ctx context.Context
  54. }
  55. // Do executes the request and returns response or error.
  56. func (r IndicesGetTemplateRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  57. var (
  58. method string
  59. path strings.Builder
  60. params map[string]string
  61. )
  62. method = "GET"
  63. path.Grow(1 + len("_template") + 1 + len(strings.Join(r.Name, ",")))
  64. path.WriteString("/")
  65. path.WriteString("_template")
  66. if len(r.Name) > 0 {
  67. path.WriteString("/")
  68. path.WriteString(strings.Join(r.Name, ","))
  69. }
  70. params = make(map[string]string)
  71. if r.FlatSettings != nil {
  72. params["flat_settings"] = strconv.FormatBool(*r.FlatSettings)
  73. }
  74. if r.IncludeTypeName != nil {
  75. params["include_type_name"] = strconv.FormatBool(*r.IncludeTypeName)
  76. }
  77. if r.Local != nil {
  78. params["local"] = strconv.FormatBool(*r.Local)
  79. }
  80. if r.MasterTimeout != 0 {
  81. params["master_timeout"] = formatDuration(r.MasterTimeout)
  82. }
  83. if r.Pretty {
  84. params["pretty"] = "true"
  85. }
  86. if r.Human {
  87. params["human"] = "true"
  88. }
  89. if r.ErrorTrace {
  90. params["error_trace"] = "true"
  91. }
  92. if len(r.FilterPath) > 0 {
  93. params["filter_path"] = strings.Join(r.FilterPath, ",")
  94. }
  95. req, err := newRequest(method, path.String(), nil)
  96. if err != nil {
  97. return nil, err
  98. }
  99. if len(params) > 0 {
  100. q := req.URL.Query()
  101. for k, v := range params {
  102. q.Set(k, v)
  103. }
  104. req.URL.RawQuery = q.Encode()
  105. }
  106. if len(r.Header) > 0 {
  107. if len(req.Header) == 0 {
  108. req.Header = r.Header
  109. } else {
  110. for k, vv := range r.Header {
  111. for _, v := range vv {
  112. req.Header.Add(k, v)
  113. }
  114. }
  115. }
  116. }
  117. if ctx != nil {
  118. req = req.WithContext(ctx)
  119. }
  120. res, err := transport.Perform(req)
  121. if err != nil {
  122. return nil, err
  123. }
  124. response := Response{
  125. StatusCode: res.StatusCode,
  126. Body: res.Body,
  127. Header: res.Header,
  128. }
  129. return &response, nil
  130. }
  131. // WithContext sets the request context.
  132. func (f IndicesGetTemplate) WithContext(v context.Context) func(*IndicesGetTemplateRequest) {
  133. return func(r *IndicesGetTemplateRequest) {
  134. r.ctx = v
  135. }
  136. }
  137. // WithName - the comma separated names of the index templates.
  138. func (f IndicesGetTemplate) WithName(v ...string) func(*IndicesGetTemplateRequest) {
  139. return func(r *IndicesGetTemplateRequest) {
  140. r.Name = v
  141. }
  142. }
  143. // WithFlatSettings - return settings in flat format (default: false).
  144. func (f IndicesGetTemplate) WithFlatSettings(v bool) func(*IndicesGetTemplateRequest) {
  145. return func(r *IndicesGetTemplateRequest) {
  146. r.FlatSettings = &v
  147. }
  148. }
  149. // WithIncludeTypeName - whether a type should be returned in the body of the mappings..
  150. func (f IndicesGetTemplate) WithIncludeTypeName(v bool) func(*IndicesGetTemplateRequest) {
  151. return func(r *IndicesGetTemplateRequest) {
  152. r.IncludeTypeName = &v
  153. }
  154. }
  155. // WithLocal - return local information, do not retrieve the state from master node (default: false).
  156. func (f IndicesGetTemplate) WithLocal(v bool) func(*IndicesGetTemplateRequest) {
  157. return func(r *IndicesGetTemplateRequest) {
  158. r.Local = &v
  159. }
  160. }
  161. // WithMasterTimeout - explicit operation timeout for connection to master node.
  162. func (f IndicesGetTemplate) WithMasterTimeout(v time.Duration) func(*IndicesGetTemplateRequest) {
  163. return func(r *IndicesGetTemplateRequest) {
  164. r.MasterTimeout = v
  165. }
  166. }
  167. // WithPretty makes the response body pretty-printed.
  168. func (f IndicesGetTemplate) WithPretty() func(*IndicesGetTemplateRequest) {
  169. return func(r *IndicesGetTemplateRequest) {
  170. r.Pretty = true
  171. }
  172. }
  173. // WithHuman makes statistical values human-readable.
  174. func (f IndicesGetTemplate) WithHuman() func(*IndicesGetTemplateRequest) {
  175. return func(r *IndicesGetTemplateRequest) {
  176. r.Human = true
  177. }
  178. }
  179. // WithErrorTrace includes the stack trace for errors in the response body.
  180. func (f IndicesGetTemplate) WithErrorTrace() func(*IndicesGetTemplateRequest) {
  181. return func(r *IndicesGetTemplateRequest) {
  182. r.ErrorTrace = true
  183. }
  184. }
  185. // WithFilterPath filters the properties of the response body.
  186. func (f IndicesGetTemplate) WithFilterPath(v ...string) func(*IndicesGetTemplateRequest) {
  187. return func(r *IndicesGetTemplateRequest) {
  188. r.FilterPath = v
  189. }
  190. }
  191. // WithHeader adds the headers to the HTTP request.
  192. func (f IndicesGetTemplate) WithHeader(h map[string]string) func(*IndicesGetTemplateRequest) {
  193. return func(r *IndicesGetTemplateRequest) {
  194. if r.Header == nil {
  195. r.Header = make(http.Header)
  196. }
  197. for k, v := range h {
  198. r.Header.Add(k, v)
  199. }
  200. }
  201. }
  202. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  203. func (f IndicesGetTemplate) WithOpaqueID(s string) func(*IndicesGetTemplateRequest) {
  204. return func(r *IndicesGetTemplateRequest) {
  205. if r.Header == nil {
  206. r.Header = make(http.Header)
  207. }
  208. r.Header.Set("X-Opaque-Id", s)
  209. }
  210. }