api.xpack.watcher.activate_watch.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 newWatcherActivateWatchFunc(t Transport) WatcherActivateWatch {
  26. return func(watch_id string, o ...func(*WatcherActivateWatchRequest)) (*Response, error) {
  27. var r = WatcherActivateWatchRequest{WatchID: watch_id}
  28. for _, f := range o {
  29. f(&r)
  30. }
  31. return r.Do(r.ctx, t)
  32. }
  33. }
  34. // ----- API Definition -------------------------------------------------------
  35. // WatcherActivateWatch - Activates a currently inactive watch.
  36. //
  37. // See full documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/watcher-api-activate-watch.html.
  38. type WatcherActivateWatch func(watch_id string, o ...func(*WatcherActivateWatchRequest)) (*Response, error)
  39. // WatcherActivateWatchRequest configures the Watcher Activate Watch API request.
  40. type WatcherActivateWatchRequest struct {
  41. WatchID 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 WatcherActivateWatchRequest) 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 = "PUT"
  57. path.Grow(1 + len("_watcher") + 1 + len("watch") + 1 + len(r.WatchID) + 1 + len("_activate"))
  58. path.WriteString("/")
  59. path.WriteString("_watcher")
  60. path.WriteString("/")
  61. path.WriteString("watch")
  62. path.WriteString("/")
  63. path.WriteString(r.WatchID)
  64. path.WriteString("/")
  65. path.WriteString("_activate")
  66. params = make(map[string]string)
  67. if r.Pretty {
  68. params["pretty"] = "true"
  69. }
  70. if r.Human {
  71. params["human"] = "true"
  72. }
  73. if r.ErrorTrace {
  74. params["error_trace"] = "true"
  75. }
  76. if len(r.FilterPath) > 0 {
  77. params["filter_path"] = strings.Join(r.FilterPath, ",")
  78. }
  79. req, err := newRequest(method, path.String(), nil)
  80. if err != nil {
  81. return nil, err
  82. }
  83. if len(params) > 0 {
  84. q := req.URL.Query()
  85. for k, v := range params {
  86. q.Set(k, v)
  87. }
  88. req.URL.RawQuery = q.Encode()
  89. }
  90. if len(r.Header) > 0 {
  91. if len(req.Header) == 0 {
  92. req.Header = r.Header
  93. } else {
  94. for k, vv := range r.Header {
  95. for _, v := range vv {
  96. req.Header.Add(k, v)
  97. }
  98. }
  99. }
  100. }
  101. if ctx != nil {
  102. req = req.WithContext(ctx)
  103. }
  104. res, err := transport.Perform(req)
  105. if err != nil {
  106. return nil, err
  107. }
  108. response := Response{
  109. StatusCode: res.StatusCode,
  110. Body: res.Body,
  111. Header: res.Header,
  112. }
  113. return &response, nil
  114. }
  115. // WithContext sets the request context.
  116. func (f WatcherActivateWatch) WithContext(v context.Context) func(*WatcherActivateWatchRequest) {
  117. return func(r *WatcherActivateWatchRequest) {
  118. r.ctx = v
  119. }
  120. }
  121. // WithPretty makes the response body pretty-printed.
  122. func (f WatcherActivateWatch) WithPretty() func(*WatcherActivateWatchRequest) {
  123. return func(r *WatcherActivateWatchRequest) {
  124. r.Pretty = true
  125. }
  126. }
  127. // WithHuman makes statistical values human-readable.
  128. func (f WatcherActivateWatch) WithHuman() func(*WatcherActivateWatchRequest) {
  129. return func(r *WatcherActivateWatchRequest) {
  130. r.Human = true
  131. }
  132. }
  133. // WithErrorTrace includes the stack trace for errors in the response body.
  134. func (f WatcherActivateWatch) WithErrorTrace() func(*WatcherActivateWatchRequest) {
  135. return func(r *WatcherActivateWatchRequest) {
  136. r.ErrorTrace = true
  137. }
  138. }
  139. // WithFilterPath filters the properties of the response body.
  140. func (f WatcherActivateWatch) WithFilterPath(v ...string) func(*WatcherActivateWatchRequest) {
  141. return func(r *WatcherActivateWatchRequest) {
  142. r.FilterPath = v
  143. }
  144. }
  145. // WithHeader adds the headers to the HTTP request.
  146. func (f WatcherActivateWatch) WithHeader(h map[string]string) func(*WatcherActivateWatchRequest) {
  147. return func(r *WatcherActivateWatchRequest) {
  148. if r.Header == nil {
  149. r.Header = make(http.Header)
  150. }
  151. for k, v := range h {
  152. r.Header.Add(k, v)
  153. }
  154. }
  155. }
  156. // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
  157. func (f WatcherActivateWatch) WithOpaqueID(s string) func(*WatcherActivateWatchRequest) {
  158. return func(r *WatcherActivateWatchRequest) {
  159. if r.Header == nil {
  160. r.Header = make(http.Header)
  161. }
  162. r.Header.Set("X-Opaque-Id", s)
  163. }
  164. }