github.com/opensearch-project/opensearch-go/v2@v2.3.0/opensearchapi/api.indices.get_settings.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 newIndicesGetSettingsFunc(t Transport) IndicesGetSettings { 38 return func(o ...func(*IndicesGetSettingsRequest)) (*Response, error) { 39 var r = IndicesGetSettingsRequest{} 40 for _, f := range o { 41 f(&r) 42 } 43 return r.Do(r.ctx, t) 44 } 45 } 46 47 // ----- API Definition ------------------------------------------------------- 48 49 // IndicesGetSettings returns settings for one or more indices. 50 // 51 // 52 type IndicesGetSettings func(o ...func(*IndicesGetSettingsRequest)) (*Response, error) 53 54 // IndicesGetSettingsRequest configures the Indices Get Settings API request. 55 // 56 type IndicesGetSettingsRequest struct { 57 Index []string 58 59 Name []string 60 61 AllowNoIndices *bool 62 ExpandWildcards string 63 FlatSettings *bool 64 IgnoreUnavailable *bool 65 IncludeDefaults *bool 66 Local *bool 67 MasterTimeout time.Duration 68 ClusterManagerTimeout time.Duration 69 70 Pretty bool 71 Human bool 72 ErrorTrace bool 73 FilterPath []string 74 75 Header http.Header 76 77 ctx context.Context 78 } 79 80 // Do executes the request and returns response or error. 81 // 82 func (r IndicesGetSettingsRequest) Do(ctx context.Context, transport Transport) (*Response, error) { 83 var ( 84 method string 85 path strings.Builder 86 params map[string]string 87 ) 88 89 method = "GET" 90 91 path.Grow(1 + len(strings.Join(r.Index, ",")) + 1 + len("_settings") + 1 + len(strings.Join(r.Name, ","))) 92 if len(r.Index) > 0 { 93 path.WriteString("/") 94 path.WriteString(strings.Join(r.Index, ",")) 95 } 96 path.WriteString("/") 97 path.WriteString("_settings") 98 if len(r.Name) > 0 { 99 path.WriteString("/") 100 path.WriteString(strings.Join(r.Name, ",")) 101 } 102 103 params = make(map[string]string) 104 105 if r.AllowNoIndices != nil { 106 params["allow_no_indices"] = strconv.FormatBool(*r.AllowNoIndices) 107 } 108 109 if r.ExpandWildcards != "" { 110 params["expand_wildcards"] = r.ExpandWildcards 111 } 112 113 if r.FlatSettings != nil { 114 params["flat_settings"] = strconv.FormatBool(*r.FlatSettings) 115 } 116 117 if r.IgnoreUnavailable != nil { 118 params["ignore_unavailable"] = strconv.FormatBool(*r.IgnoreUnavailable) 119 } 120 121 if r.IncludeDefaults != nil { 122 params["include_defaults"] = strconv.FormatBool(*r.IncludeDefaults) 123 } 124 125 if r.Local != nil { 126 params["local"] = strconv.FormatBool(*r.Local) 127 } 128 129 if r.MasterTimeout != 0 { 130 params["master_timeout"] = formatDuration(r.MasterTimeout) 131 } 132 133 if r.ClusterManagerTimeout != 0 { 134 params["cluster_manager_timeout"] = formatDuration(r.ClusterManagerTimeout) 135 } 136 137 if r.Pretty { 138 params["pretty"] = "true" 139 } 140 141 if r.Human { 142 params["human"] = "true" 143 } 144 145 if r.ErrorTrace { 146 params["error_trace"] = "true" 147 } 148 149 if len(r.FilterPath) > 0 { 150 params["filter_path"] = strings.Join(r.FilterPath, ",") 151 } 152 153 req, err := newRequest(method, path.String(), nil) 154 if err != nil { 155 return nil, err 156 } 157 158 if len(params) > 0 { 159 q := req.URL.Query() 160 for k, v := range params { 161 q.Set(k, v) 162 } 163 req.URL.RawQuery = q.Encode() 164 } 165 166 if len(r.Header) > 0 { 167 if len(req.Header) == 0 { 168 req.Header = r.Header 169 } else { 170 for k, vv := range r.Header { 171 for _, v := range vv { 172 req.Header.Add(k, v) 173 } 174 } 175 } 176 } 177 178 if ctx != nil { 179 req = req.WithContext(ctx) 180 } 181 182 res, err := transport.Perform(req) 183 if err != nil { 184 return nil, err 185 } 186 187 response := Response{ 188 StatusCode: res.StatusCode, 189 Body: res.Body, 190 Header: res.Header, 191 } 192 193 return &response, nil 194 } 195 196 // WithContext sets the request context. 197 // 198 func (f IndicesGetSettings) WithContext(v context.Context) func(*IndicesGetSettingsRequest) { 199 return func(r *IndicesGetSettingsRequest) { 200 r.ctx = v 201 } 202 } 203 204 // WithIndex - a list of index names; use _all to perform the operation on all indices. 205 // 206 func (f IndicesGetSettings) WithIndex(v ...string) func(*IndicesGetSettingsRequest) { 207 return func(r *IndicesGetSettingsRequest) { 208 r.Index = v 209 } 210 } 211 212 // WithName - the name of the settings that should be included. 213 // 214 func (f IndicesGetSettings) WithName(v ...string) func(*IndicesGetSettingsRequest) { 215 return func(r *IndicesGetSettingsRequest) { 216 r.Name = v 217 } 218 } 219 220 // WithAllowNoIndices - whether to ignore if a wildcard indices expression resolves into no concrete indices. (this includes `_all` string or when no indices have been specified). 221 // 222 func (f IndicesGetSettings) WithAllowNoIndices(v bool) func(*IndicesGetSettingsRequest) { 223 return func(r *IndicesGetSettingsRequest) { 224 r.AllowNoIndices = &v 225 } 226 } 227 228 // WithExpandWildcards - whether to expand wildcard expression to concrete indices that are open, closed or both.. 229 // 230 func (f IndicesGetSettings) WithExpandWildcards(v string) func(*IndicesGetSettingsRequest) { 231 return func(r *IndicesGetSettingsRequest) { 232 r.ExpandWildcards = v 233 } 234 } 235 236 // WithFlatSettings - return settings in flat format (default: false). 237 // 238 func (f IndicesGetSettings) WithFlatSettings(v bool) func(*IndicesGetSettingsRequest) { 239 return func(r *IndicesGetSettingsRequest) { 240 r.FlatSettings = &v 241 } 242 } 243 244 // WithIgnoreUnavailable - whether specified concrete indices should be ignored when unavailable (missing or closed). 245 // 246 func (f IndicesGetSettings) WithIgnoreUnavailable(v bool) func(*IndicesGetSettingsRequest) { 247 return func(r *IndicesGetSettingsRequest) { 248 r.IgnoreUnavailable = &v 249 } 250 } 251 252 // WithIncludeDefaults - whether to return all default setting for each of the indices.. 253 // 254 func (f IndicesGetSettings) WithIncludeDefaults(v bool) func(*IndicesGetSettingsRequest) { 255 return func(r *IndicesGetSettingsRequest) { 256 r.IncludeDefaults = &v 257 } 258 } 259 260 // WithLocal - return local information, do not retrieve the state from cluster-manager node (default: false). 261 // 262 func (f IndicesGetSettings) WithLocal(v bool) func(*IndicesGetSettingsRequest) { 263 return func(r *IndicesGetSettingsRequest) { 264 r.Local = &v 265 } 266 } 267 268 // WithMasterTimeout - explicit operation timeout for connection to cluster-manager node. 269 // 270 // Deprecated: To promote inclusive language, use WithClusterManagerTimeout instead. 271 // 272 func (f IndicesGetSettings) WithMasterTimeout(v time.Duration) func(*IndicesGetSettingsRequest) { 273 return func(r *IndicesGetSettingsRequest) { 274 r.MasterTimeout = v 275 } 276 } 277 278 // WithClusterManagerTimeout - explicit operation timeout for connection to cluster-manager node. 279 // 280 func (f IndicesGetSettings) WithClusterManagerTimeout(v time.Duration) func(*IndicesGetSettingsRequest) { 281 return func(r *IndicesGetSettingsRequest) { 282 r.ClusterManagerTimeout = v 283 } 284 } 285 286 // WithPretty makes the response body pretty-printed. 287 // 288 func (f IndicesGetSettings) WithPretty() func(*IndicesGetSettingsRequest) { 289 return func(r *IndicesGetSettingsRequest) { 290 r.Pretty = true 291 } 292 } 293 294 // WithHuman makes statistical values human-readable. 295 // 296 func (f IndicesGetSettings) WithHuman() func(*IndicesGetSettingsRequest) { 297 return func(r *IndicesGetSettingsRequest) { 298 r.Human = true 299 } 300 } 301 302 // WithErrorTrace includes the stack trace for errors in the response body. 303 // 304 func (f IndicesGetSettings) WithErrorTrace() func(*IndicesGetSettingsRequest) { 305 return func(r *IndicesGetSettingsRequest) { 306 r.ErrorTrace = true 307 } 308 } 309 310 // WithFilterPath filters the properties of the response body. 311 // 312 func (f IndicesGetSettings) WithFilterPath(v ...string) func(*IndicesGetSettingsRequest) { 313 return func(r *IndicesGetSettingsRequest) { 314 r.FilterPath = v 315 } 316 } 317 318 // WithHeader adds the headers to the HTTP request. 319 // 320 func (f IndicesGetSettings) WithHeader(h map[string]string) func(*IndicesGetSettingsRequest) { 321 return func(r *IndicesGetSettingsRequest) { 322 if r.Header == nil { 323 r.Header = make(http.Header) 324 } 325 for k, v := range h { 326 r.Header.Add(k, v) 327 } 328 } 329 } 330 331 // WithOpaqueID adds the X-Opaque-Id header to the HTTP request. 332 // 333 func (f IndicesGetSettings) WithOpaqueID(s string) func(*IndicesGetSettingsRequest) { 334 return func(r *IndicesGetSettingsRequest) { 335 if r.Header == nil { 336 r.Header = make(http.Header) 337 } 338 r.Header.Set("X-Opaque-Id", s) 339 } 340 }