github.com/opensearch-project/opensearch-go/v2@v2.3.0/opensearchapi/api.ingest.delete_pipeline.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // 3 // The OpenSearch Contributors require contributions made to 4 // this file be licensed under the Apache-2.0 license or a 5 // compatible open source license. 6 // 7 // Modifications Copyright OpenSearch Contributors. See 8 // GitHub history for details. 9 10 // Licensed to Elasticsearch B.V. under one or more contributor 11 // license agreements. See the NOTICE file distributed with 12 // this work for additional information regarding copyright 13 // ownership. Elasticsearch B.V. licenses this file to you under 14 // the Apache License, Version 2.0 (the "License"); you may 15 // not use this file except in compliance with the License. 16 // You may obtain a copy of the License at 17 // 18 // http://www.apache.org/licenses/LICENSE-2.0 19 // 20 // Unless required by applicable law or agreed to in writing, 21 // software distributed under the License is distributed on an 22 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 23 // KIND, either express or implied. See the License for the 24 // specific language governing permissions and limitations 25 // under the License. 26 27 package opensearchapi 28 29 import ( 30 "context" 31 "net/http" 32 "strings" 33 "time" 34 ) 35 36 func newIngestDeletePipelineFunc(t Transport) IngestDeletePipeline { 37 return func(id string, o ...func(*IngestDeletePipelineRequest)) (*Response, error) { 38 var r = IngestDeletePipelineRequest{PipelineID: id} 39 for _, f := range o { 40 f(&r) 41 } 42 return r.Do(r.ctx, t) 43 } 44 } 45 46 // ----- API Definition ------------------------------------------------------- 47 48 // IngestDeletePipeline deletes a pipeline. 49 // 50 // 51 type IngestDeletePipeline func(id string, o ...func(*IngestDeletePipelineRequest)) (*Response, error) 52 53 // IngestDeletePipelineRequest configures the Ingest Delete Pipeline API request. 54 // 55 type IngestDeletePipelineRequest struct { 56 PipelineID string 57 58 MasterTimeout time.Duration 59 ClusterManagerTimeout time.Duration 60 Timeout time.Duration 61 62 Pretty bool 63 Human bool 64 ErrorTrace bool 65 FilterPath []string 66 67 Header http.Header 68 69 ctx context.Context 70 } 71 72 // Do executes the request and returns response or error. 73 // 74 func (r IngestDeletePipelineRequest) Do(ctx context.Context, transport Transport) (*Response, error) { 75 var ( 76 method string 77 path strings.Builder 78 params map[string]string 79 ) 80 81 method = "DELETE" 82 83 path.Grow(1 + len("_ingest") + 1 + len("pipeline") + 1 + len(r.PipelineID)) 84 path.WriteString("/") 85 path.WriteString("_ingest") 86 path.WriteString("/") 87 path.WriteString("pipeline") 88 path.WriteString("/") 89 path.WriteString(r.PipelineID) 90 91 params = make(map[string]string) 92 93 if r.MasterTimeout != 0 { 94 params["master_timeout"] = formatDuration(r.MasterTimeout) 95 } 96 97 if r.ClusterManagerTimeout != 0 { 98 params["cluster_manager_timeout"] = formatDuration(r.ClusterManagerTimeout) 99 } 100 101 if r.Timeout != 0 { 102 params["timeout"] = formatDuration(r.Timeout) 103 } 104 105 if r.Pretty { 106 params["pretty"] = "true" 107 } 108 109 if r.Human { 110 params["human"] = "true" 111 } 112 113 if r.ErrorTrace { 114 params["error_trace"] = "true" 115 } 116 117 if len(r.FilterPath) > 0 { 118 params["filter_path"] = strings.Join(r.FilterPath, ",") 119 } 120 121 req, err := newRequest(method, path.String(), nil) 122 if err != nil { 123 return nil, err 124 } 125 126 if len(params) > 0 { 127 q := req.URL.Query() 128 for k, v := range params { 129 q.Set(k, v) 130 } 131 req.URL.RawQuery = q.Encode() 132 } 133 134 if len(r.Header) > 0 { 135 if len(req.Header) == 0 { 136 req.Header = r.Header 137 } else { 138 for k, vv := range r.Header { 139 for _, v := range vv { 140 req.Header.Add(k, v) 141 } 142 } 143 } 144 } 145 146 if ctx != nil { 147 req = req.WithContext(ctx) 148 } 149 150 res, err := transport.Perform(req) 151 if err != nil { 152 return nil, err 153 } 154 155 response := Response{ 156 StatusCode: res.StatusCode, 157 Body: res.Body, 158 Header: res.Header, 159 } 160 161 return &response, nil 162 } 163 164 // WithContext sets the request context. 165 // 166 func (f IngestDeletePipeline) WithContext(v context.Context) func(*IngestDeletePipelineRequest) { 167 return func(r *IngestDeletePipelineRequest) { 168 r.ctx = v 169 } 170 } 171 172 // WithMasterTimeout - explicit operation timeout for connection to cluster-manager node. 173 // 174 // Deprecated: To promote inclusive language, use WithClusterManagerTimeout instead. 175 // 176 func (f IngestDeletePipeline) WithMasterTimeout(v time.Duration) func(*IngestDeletePipelineRequest) { 177 return func(r *IngestDeletePipelineRequest) { 178 r.MasterTimeout = v 179 } 180 } 181 182 // WithClusterManagerTimeout - explicit operation timeout for connection to cluster-manager node. 183 // 184 func (f IngestDeletePipeline) WithClusterManagerTimeout(v time.Duration) func(*IngestDeletePipelineRequest) { 185 return func(r *IngestDeletePipelineRequest) { 186 r.ClusterManagerTimeout = v 187 } 188 } 189 190 // WithTimeout - explicit operation timeout. 191 // 192 func (f IngestDeletePipeline) WithTimeout(v time.Duration) func(*IngestDeletePipelineRequest) { 193 return func(r *IngestDeletePipelineRequest) { 194 r.Timeout = v 195 } 196 } 197 198 // WithPretty makes the response body pretty-printed. 199 // 200 func (f IngestDeletePipeline) WithPretty() func(*IngestDeletePipelineRequest) { 201 return func(r *IngestDeletePipelineRequest) { 202 r.Pretty = true 203 } 204 } 205 206 // WithHuman makes statistical values human-readable. 207 // 208 func (f IngestDeletePipeline) WithHuman() func(*IngestDeletePipelineRequest) { 209 return func(r *IngestDeletePipelineRequest) { 210 r.Human = true 211 } 212 } 213 214 // WithErrorTrace includes the stack trace for errors in the response body. 215 // 216 func (f IngestDeletePipeline) WithErrorTrace() func(*IngestDeletePipelineRequest) { 217 return func(r *IngestDeletePipelineRequest) { 218 r.ErrorTrace = true 219 } 220 } 221 222 // WithFilterPath filters the properties of the response body. 223 // 224 func (f IngestDeletePipeline) WithFilterPath(v ...string) func(*IngestDeletePipelineRequest) { 225 return func(r *IngestDeletePipelineRequest) { 226 r.FilterPath = v 227 } 228 } 229 230 // WithHeader adds the headers to the HTTP request. 231 // 232 func (f IngestDeletePipeline) WithHeader(h map[string]string) func(*IngestDeletePipelineRequest) { 233 return func(r *IngestDeletePipelineRequest) { 234 if r.Header == nil { 235 r.Header = make(http.Header) 236 } 237 for k, v := range h { 238 r.Header.Add(k, v) 239 } 240 } 241 } 242 243 // WithOpaqueID adds the X-Opaque-Id header to the HTTP request. 244 // 245 func (f IngestDeletePipeline) WithOpaqueID(s string) func(*IngestDeletePipelineRequest) { 246 return func(r *IngestDeletePipelineRequest) { 247 if r.Header == nil { 248 r.Header = make(http.Header) 249 } 250 r.Header.Set("X-Opaque-Id", s) 251 } 252 }