github.com/opensearch-project/opensearch-go/v2@v2.3.0/opensearchapi/api.cluster.delete_voting_config_exclusions.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  )
    35  
    36  func newClusterDeleteVotingConfigExclusionsFunc(t Transport) ClusterDeleteVotingConfigExclusions {
    37  	return func(o ...func(*ClusterDeleteVotingConfigExclusionsRequest)) (*Response, error) {
    38  		var r = ClusterDeleteVotingConfigExclusionsRequest{}
    39  		for _, f := range o {
    40  			f(&r)
    41  		}
    42  		return r.Do(r.ctx, t)
    43  	}
    44  }
    45  
    46  // ----- API Definition -------------------------------------------------------
    47  
    48  // ClusterDeleteVotingConfigExclusions clears cluster voting config exclusions.
    49  //
    50  //
    51  type ClusterDeleteVotingConfigExclusions func(o ...func(*ClusterDeleteVotingConfigExclusionsRequest)) (*Response, error)
    52  
    53  // ClusterDeleteVotingConfigExclusionsRequest configures the Cluster Delete Voting Config Exclusions API request.
    54  //
    55  type ClusterDeleteVotingConfigExclusionsRequest struct {
    56  	WaitForRemoval *bool
    57  
    58  	Pretty     bool
    59  	Human      bool
    60  	ErrorTrace bool
    61  	FilterPath []string
    62  
    63  	Header http.Header
    64  
    65  	ctx context.Context
    66  }
    67  
    68  // Do executes the request and returns response or error.
    69  //
    70  func (r ClusterDeleteVotingConfigExclusionsRequest) Do(ctx context.Context, transport Transport) (*Response, error) {
    71  	var (
    72  		method string
    73  		path   strings.Builder
    74  		params map[string]string
    75  	)
    76  
    77  	method = "DELETE"
    78  
    79  	path.Grow(len("/_cluster/voting_config_exclusions"))
    80  	path.WriteString("/_cluster/voting_config_exclusions")
    81  
    82  	params = make(map[string]string)
    83  
    84  	if r.WaitForRemoval != nil {
    85  		params["wait_for_removal"] = strconv.FormatBool(*r.WaitForRemoval)
    86  	}
    87  
    88  	if r.Pretty {
    89  		params["pretty"] = "true"
    90  	}
    91  
    92  	if r.Human {
    93  		params["human"] = "true"
    94  	}
    95  
    96  	if r.ErrorTrace {
    97  		params["error_trace"] = "true"
    98  	}
    99  
   100  	if len(r.FilterPath) > 0 {
   101  		params["filter_path"] = strings.Join(r.FilterPath, ",")
   102  	}
   103  
   104  	req, err := newRequest(method, path.String(), nil)
   105  	if err != nil {
   106  		return nil, err
   107  	}
   108  
   109  	if len(params) > 0 {
   110  		q := req.URL.Query()
   111  		for k, v := range params {
   112  			q.Set(k, v)
   113  		}
   114  		req.URL.RawQuery = q.Encode()
   115  	}
   116  
   117  	if len(r.Header) > 0 {
   118  		if len(req.Header) == 0 {
   119  			req.Header = r.Header
   120  		} else {
   121  			for k, vv := range r.Header {
   122  				for _, v := range vv {
   123  					req.Header.Add(k, v)
   124  				}
   125  			}
   126  		}
   127  	}
   128  
   129  	if ctx != nil {
   130  		req = req.WithContext(ctx)
   131  	}
   132  
   133  	res, err := transport.Perform(req)
   134  	if err != nil {
   135  		return nil, err
   136  	}
   137  
   138  	response := Response{
   139  		StatusCode: res.StatusCode,
   140  		Body:       res.Body,
   141  		Header:     res.Header,
   142  	}
   143  
   144  	return &response, nil
   145  }
   146  
   147  // WithContext sets the request context.
   148  //
   149  func (f ClusterDeleteVotingConfigExclusions) WithContext(v context.Context) func(*ClusterDeleteVotingConfigExclusionsRequest) {
   150  	return func(r *ClusterDeleteVotingConfigExclusionsRequest) {
   151  		r.ctx = v
   152  	}
   153  }
   154  
   155  // WithWaitForRemoval - specifies whether to wait for all excluded nodes to be removed from the cluster before clearing the voting configuration exclusions list..
   156  //
   157  func (f ClusterDeleteVotingConfigExclusions) WithWaitForRemoval(v bool) func(*ClusterDeleteVotingConfigExclusionsRequest) {
   158  	return func(r *ClusterDeleteVotingConfigExclusionsRequest) {
   159  		r.WaitForRemoval = &v
   160  	}
   161  }
   162  
   163  // WithPretty makes the response body pretty-printed.
   164  //
   165  func (f ClusterDeleteVotingConfigExclusions) WithPretty() func(*ClusterDeleteVotingConfigExclusionsRequest) {
   166  	return func(r *ClusterDeleteVotingConfigExclusionsRequest) {
   167  		r.Pretty = true
   168  	}
   169  }
   170  
   171  // WithHuman makes statistical values human-readable.
   172  //
   173  func (f ClusterDeleteVotingConfigExclusions) WithHuman() func(*ClusterDeleteVotingConfigExclusionsRequest) {
   174  	return func(r *ClusterDeleteVotingConfigExclusionsRequest) {
   175  		r.Human = true
   176  	}
   177  }
   178  
   179  // WithErrorTrace includes the stack trace for errors in the response body.
   180  //
   181  func (f ClusterDeleteVotingConfigExclusions) WithErrorTrace() func(*ClusterDeleteVotingConfigExclusionsRequest) {
   182  	return func(r *ClusterDeleteVotingConfigExclusionsRequest) {
   183  		r.ErrorTrace = true
   184  	}
   185  }
   186  
   187  // WithFilterPath filters the properties of the response body.
   188  //
   189  func (f ClusterDeleteVotingConfigExclusions) WithFilterPath(v ...string) func(*ClusterDeleteVotingConfigExclusionsRequest) {
   190  	return func(r *ClusterDeleteVotingConfigExclusionsRequest) {
   191  		r.FilterPath = v
   192  	}
   193  }
   194  
   195  // WithHeader adds the headers to the HTTP request.
   196  //
   197  func (f ClusterDeleteVotingConfigExclusions) WithHeader(h map[string]string) func(*ClusterDeleteVotingConfigExclusionsRequest) {
   198  	return func(r *ClusterDeleteVotingConfigExclusionsRequest) {
   199  		if r.Header == nil {
   200  			r.Header = make(http.Header)
   201  		}
   202  		for k, v := range h {
   203  			r.Header.Add(k, v)
   204  		}
   205  	}
   206  }
   207  
   208  // WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
   209  //
   210  func (f ClusterDeleteVotingConfigExclusions) WithOpaqueID(s string) func(*ClusterDeleteVotingConfigExclusionsRequest) {
   211  	return func(r *ClusterDeleteVotingConfigExclusionsRequest) {
   212  		if r.Header == nil {
   213  			r.Header = make(http.Header)
   214  		}
   215  		r.Header.Set("X-Opaque-Id", s)
   216  	}
   217  }