github.com/opensearch-project/opensearch-go/v2@v2.3.0/opensearchapi/api.ingest.get_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 "strconv" 33 "strings" 34 "time" 35 ) 36 37 func newIngestGetPipelineFunc(t Transport) IngestGetPipeline { 38 return func(o ...func(*IngestGetPipelineRequest)) (*Response, error) { 39 var r = IngestGetPipelineRequest{} 40 for _, f := range o { 41 f(&r) 42 } 43 return r.Do(r.ctx, t) 44 } 45 } 46 47 // ----- API Definition ------------------------------------------------------- 48 49 // IngestGetPipeline returns a pipeline. 50 // 51 // 52 type IngestGetPipeline func(o ...func(*IngestGetPipelineRequest)) (*Response, error) 53 54 // IngestGetPipelineRequest configures the Ingest Get Pipeline API request. 55 // 56 type IngestGetPipelineRequest struct { 57 PipelineID string 58 59 MasterTimeout time.Duration 60 ClusterManagerTimeout time.Duration 61 Summary *bool 62 63 Pretty bool 64 Human bool 65 ErrorTrace bool 66 FilterPath []string 67 68 Header http.Header 69 70 ctx context.Context 71 } 72 73 // Do executes the request and returns response or error. 74 // 75 func (r IngestGetPipelineRequest) Do(ctx context.Context, transport Transport) (*Response, error) { 76 var ( 77 method string 78 path strings.Builder 79 params map[string]string 80 ) 81 82 method = "GET" 83 84 path.Grow(1 + len("_ingest") + 1 + len("pipeline") + 1 + len(r.PipelineID)) 85 path.WriteString("/") 86 path.WriteString("_ingest") 87 path.WriteString("/") 88 path.WriteString("pipeline") 89 if r.PipelineID != "" { 90 path.WriteString("/") 91 path.WriteString(r.PipelineID) 92 } 93 94 params = make(map[string]string) 95 96 if r.MasterTimeout != 0 { 97 params["master_timeout"] = formatDuration(r.MasterTimeout) 98 } 99 100 if r.ClusterManagerTimeout != 0 { 101 params["cluster_manager_timeout"] = formatDuration(r.ClusterManagerTimeout) 102 } 103 104 if r.Summary != nil { 105 params["summary"] = strconv.FormatBool(*r.Summary) 106 } 107 108 if r.Pretty { 109 params["pretty"] = "true" 110 } 111 112 if r.Human { 113 params["human"] = "true" 114 } 115 116 if r.ErrorTrace { 117 params["error_trace"] = "true" 118 } 119 120 if len(r.FilterPath) > 0 { 121 params["filter_path"] = strings.Join(r.FilterPath, ",") 122 } 123 124 req, err := newRequest(method, path.String(), nil) 125 if err != nil { 126 return nil, err 127 } 128 129 if len(params) > 0 { 130 q := req.URL.Query() 131 for k, v := range params { 132 q.Set(k, v) 133 } 134 req.URL.RawQuery = q.Encode() 135 } 136 137 if len(r.Header) > 0 { 138 if len(req.Header) == 0 { 139 req.Header = r.Header 140 } else { 141 for k, vv := range r.Header { 142 for _, v := range vv { 143 req.Header.Add(k, v) 144 } 145 } 146 } 147 } 148 149 if ctx != nil { 150 req = req.WithContext(ctx) 151 } 152 153 res, err := transport.Perform(req) 154 if err != nil { 155 return nil, err 156 } 157 158 response := Response{ 159 StatusCode: res.StatusCode, 160 Body: res.Body, 161 Header: res.Header, 162 } 163 164 return &response, nil 165 } 166 167 // WithContext sets the request context. 168 // 169 func (f IngestGetPipeline) WithContext(v context.Context) func(*IngestGetPipelineRequest) { 170 return func(r *IngestGetPipelineRequest) { 171 r.ctx = v 172 } 173 } 174 175 // WithPipelineID - comma separated list of pipeline ids. wildcards supported. 176 // 177 func (f IngestGetPipeline) WithPipelineID(v string) func(*IngestGetPipelineRequest) { 178 return func(r *IngestGetPipelineRequest) { 179 r.PipelineID = v 180 } 181 } 182 183 // WithMasterTimeout - explicit operation timeout for connection to cluster-manager node. 184 // 185 // Deprecated: To promote inclusive language, use WithClusterManagerTimeout instead. 186 // 187 func (f IngestGetPipeline) WithMasterTimeout(v time.Duration) func(*IngestGetPipelineRequest) { 188 return func(r *IngestGetPipelineRequest) { 189 r.MasterTimeout = v 190 } 191 } 192 193 // WithClusterManagerTimeout - explicit operation timeout for connection to cluster-manager node. 194 // 195 func (f IngestGetPipeline) WithClusterManagerTimeout(v time.Duration) func(*IngestGetPipelineRequest) { 196 return func(r *IngestGetPipelineRequest) { 197 r.ClusterManagerTimeout = v 198 } 199 } 200 201 // WithSummary - return pipelines without their definitions (default: false). 202 // 203 func (f IngestGetPipeline) WithSummary(v bool) func(*IngestGetPipelineRequest) { 204 return func(r *IngestGetPipelineRequest) { 205 r.Summary = &v 206 } 207 } 208 209 // WithPretty makes the response body pretty-printed. 210 // 211 func (f IngestGetPipeline) WithPretty() func(*IngestGetPipelineRequest) { 212 return func(r *IngestGetPipelineRequest) { 213 r.Pretty = true 214 } 215 } 216 217 // WithHuman makes statistical values human-readable. 218 // 219 func (f IngestGetPipeline) WithHuman() func(*IngestGetPipelineRequest) { 220 return func(r *IngestGetPipelineRequest) { 221 r.Human = true 222 } 223 } 224 225 // WithErrorTrace includes the stack trace for errors in the response body. 226 // 227 func (f IngestGetPipeline) WithErrorTrace() func(*IngestGetPipelineRequest) { 228 return func(r *IngestGetPipelineRequest) { 229 r.ErrorTrace = true 230 } 231 } 232 233 // WithFilterPath filters the properties of the response body. 234 // 235 func (f IngestGetPipeline) WithFilterPath(v ...string) func(*IngestGetPipelineRequest) { 236 return func(r *IngestGetPipelineRequest) { 237 r.FilterPath = v 238 } 239 } 240 241 // WithHeader adds the headers to the HTTP request. 242 // 243 func (f IngestGetPipeline) WithHeader(h map[string]string) func(*IngestGetPipelineRequest) { 244 return func(r *IngestGetPipelineRequest) { 245 if r.Header == nil { 246 r.Header = make(http.Header) 247 } 248 for k, v := range h { 249 r.Header.Add(k, v) 250 } 251 } 252 } 253 254 // WithOpaqueID adds the X-Opaque-Id header to the HTTP request. 255 // 256 func (f IngestGetPipeline) WithOpaqueID(s string) func(*IngestGetPipelineRequest) { 257 return func(r *IngestGetPipelineRequest) { 258 if r.Header == nil { 259 r.Header = make(http.Header) 260 } 261 r.Header.Set("X-Opaque-Id", s) 262 } 263 }