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