api.shutdown.delete_node.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. "strings"
  24. )
  25. func newShutdownDeleteNodeFunc(t Transport) ShutdownDeleteNode {
  26. return func(node_id string, o ...func(*ShutdownDeleteNodeRequest)) (*Response, error) {
  27. var r = ShutdownDeleteNodeRequest{NodeID: node_id}
  28. for _, f := range o {
  29. f(&r)
  30. }
  31. return r.Do(r.ctx, t)
  32. }
  33. }
  34. // ----- API Definition -------------------------------------------------------
  35. // ShutdownDeleteNode removes a node from the shutdown list. Designed for indirect use by ECE/ESS and ECK. Direct use is not supported.
  36. //
  37. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current.
  38. type ShutdownDeleteNode func(node_id string, o ...func(*ShutdownDeleteNodeRequest)) (*Response, error)
  39. // ShutdownDeleteNodeRequest configures the Shutdown Delete Node API request.
  40. type ShutdownDeleteNodeRequest struct {
  41. NodeID string
  42. Pretty bool
  43. Human bool
  44. ErrorTrace bool
  45. FilterPath []string
  46. Header http.Header
  47. ctx context.Context
  48. }
  49. // Do executes the request and returns response or error.
  50. func (r ShutdownDeleteNodeRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
  51. var (
  52. method string
  53. path strings.Builder
  54. params map[string]string
  55. )
  56. method = "DELETE"
  57. path.Grow(1 + len("_nodes") + 1 + len(r.NodeID) + 1 + len("shutdown"))
  58. path.WriteString("/")
  59. path.WriteString("_nodes")
  60. path.WriteString("/")
  61. path.WriteString(r.NodeID)
  62. path.WriteString("/")
  63. path.WriteString("shutdown")
  64. params = make(map[string]string)
  65. if r.Pretty {
  66. params["pretty"] = "true"
  67. }
  68. if r.Human {
  69. params["human"] = "true"
  70. }
  71. if r.ErrorTrace {
  72. params["error_trace"] = "true"
  73. }
  74. if len(r.FilterPath) > 0 {
  75. params["filter_path"] = strings.Join(r.FilterPath, ",")
  76. }
  77. req, err := newRequest(method, path.String(), nil)
  78. if err != nil {
  79. return nil, err
  80. }
  81. if len(params) > 0 {
  82. q := req.URL.Query()
  83. for k, v := range params {
  84. q.Set(k, v)
  85. }
  86. req.URL.RawQuery = q.Encode()
  87. }
  88. if len(r.Header) > 0 {
  89. if len(req.Header) == 0 {
  90. req.Header = r.Header
  91. } else {
  92. for k, vv := range r.Header {
  93. for _, v := range vv {
  94. req.Header.Add(k, v)
  95. }
  96. }
  97. }
  98. }
  99. if ctx != nil {
  100. req = req.WithContext(ctx)
  101. }
  102. res, err := transport.Perform(req)
  103. if err != nil {
  104. return nil, err
  105. }
  106. response := Response{
  107. StatusCode: res.StatusCode,
  108. Body: res.Body,
  109. Header: res.Header,
  110. }
  111. return &response, nil
  112. }
  113. // WithContext sets the request context.
  114. func (f ShutdownDeleteNode) WithContext(v context.Context) func(*ShutdownDeleteNodeRequest) {
  115. return func(r *ShutdownDeleteNodeRequest) {
  116. r.ctx = v
  117. }
  118. }
  119. // WithPretty makes the response body pretty-printed.
  120. func (f ShutdownDeleteNode) WithPretty() func(*ShutdownDeleteNodeRequest) {
  121. return func(r *ShutdownDeleteNodeRequest) {
  122. r.Pretty = true
  123. }
  124. }
  125. // WithHuman makes statistical values human-readable.
  126. func (f ShutdownDeleteNode) WithHuman() func(*ShutdownDeleteNodeRequest) {
  127. return func(r *ShutdownDeleteNodeRequest) {
  128. r.Human = true
  129. }
  130. }
  131. // WithErrorTrace includes the stack trace for errors in the response body.
  132. func (f ShutdownDeleteNode) WithErrorTrace() func(*ShutdownDeleteNodeRequest) {
  133. return func(r *ShutdownDeleteNodeRequest) {
  134. r.ErrorTrace = true
  135. }
  136. }
  137. // WithFilterPath filters the properties of the response body.
  138. func (f ShutdownDeleteNode) WithFilterPath(v ...string) func(*ShutdownDeleteNodeRequest) {
  139. return func(r *ShutdownDeleteNodeRequest) {
  140. r.FilterPath = v
  141. }
  142. }
  143. // WithHeader adds the headers to the HTTP request.
  144. func (f ShutdownDeleteNode) WithHeader(h map[string]string) func(*ShutdownDeleteNodeRequest) {
  145. return func(r *ShutdownDeleteNodeRequest) {
  146. if r.Header == nil {
  147. r.Header = make(http.Header)
  148. }
  149. for k, v := range h {
  150. r.Header.Add(k, v)
  151. }
  152. }
  153. }
  154. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  155. func (f ShutdownDeleteNode) WithOpaqueID(s string) func(*ShutdownDeleteNodeRequest) {
  156. return func(r *ShutdownDeleteNodeRequest) {
  157. if r.Header == nil {
  158. r.Header = make(http.Header)
  159. }
  160. r.Header.Set("X-Opaque-Id", s)
  161. }
  162. }