github.com/rzurga/go-swagger@v0.28.1-0.20211109195225-5d1f453ffa3a/examples/todo-list/client/todos/find_parameters.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package todos
     4  
     5  // This file was generated by the swagger tool.
     6  // Editing this file might prove futile when you re-run the swagger generate command
     7  
     8  import (
     9  	"context"
    10  	"net/http"
    11  	"time"
    12  
    13  	"github.com/go-openapi/errors"
    14  	"github.com/go-openapi/runtime"
    15  	cr "github.com/go-openapi/runtime/client"
    16  	"github.com/go-openapi/strfmt"
    17  	"github.com/go-openapi/swag"
    18  )
    19  
    20  // NewFindParams creates a new FindParams object,
    21  // with the default timeout for this client.
    22  //
    23  // Default values are not hydrated, since defaults are normally applied by the API server side.
    24  //
    25  // To enforce default values in parameter, use SetDefaults or WithDefaults.
    26  func NewFindParams() *FindParams {
    27  	return &FindParams{
    28  		timeout: cr.DefaultTimeout,
    29  	}
    30  }
    31  
    32  // NewFindParamsWithTimeout creates a new FindParams object
    33  // with the ability to set a timeout on a request.
    34  func NewFindParamsWithTimeout(timeout time.Duration) *FindParams {
    35  	return &FindParams{
    36  		timeout: timeout,
    37  	}
    38  }
    39  
    40  // NewFindParamsWithContext creates a new FindParams object
    41  // with the ability to set a context for a request.
    42  func NewFindParamsWithContext(ctx context.Context) *FindParams {
    43  	return &FindParams{
    44  		Context: ctx,
    45  	}
    46  }
    47  
    48  // NewFindParamsWithHTTPClient creates a new FindParams object
    49  // with the ability to set a custom HTTPClient for a request.
    50  func NewFindParamsWithHTTPClient(client *http.Client) *FindParams {
    51  	return &FindParams{
    52  		HTTPClient: client,
    53  	}
    54  }
    55  
    56  /* FindParams contains all the parameters to send to the API endpoint
    57     for the find operation.
    58  
    59     Typically these are written to a http.Request.
    60  */
    61  type FindParams struct {
    62  
    63  	// XRateLimit.
    64  	//
    65  	// Format: int32
    66  	XRateLimit int32
    67  
    68  	// Limit.
    69  	//
    70  	// Format: int32
    71  	Limit int32
    72  
    73  	// Tags.
    74  	Tags []int32
    75  
    76  	timeout    time.Duration
    77  	Context    context.Context
    78  	HTTPClient *http.Client
    79  }
    80  
    81  // WithDefaults hydrates default values in the find params (not the query body).
    82  //
    83  // All values with no default are reset to their zero value.
    84  func (o *FindParams) WithDefaults() *FindParams {
    85  	o.SetDefaults()
    86  	return o
    87  }
    88  
    89  // SetDefaults hydrates default values in the find params (not the query body).
    90  //
    91  // All values with no default are reset to their zero value.
    92  func (o *FindParams) SetDefaults() {
    93  	// no default values defined for this parameter
    94  }
    95  
    96  // WithTimeout adds the timeout to the find params
    97  func (o *FindParams) WithTimeout(timeout time.Duration) *FindParams {
    98  	o.SetTimeout(timeout)
    99  	return o
   100  }
   101  
   102  // SetTimeout adds the timeout to the find params
   103  func (o *FindParams) SetTimeout(timeout time.Duration) {
   104  	o.timeout = timeout
   105  }
   106  
   107  // WithContext adds the context to the find params
   108  func (o *FindParams) WithContext(ctx context.Context) *FindParams {
   109  	o.SetContext(ctx)
   110  	return o
   111  }
   112  
   113  // SetContext adds the context to the find params
   114  func (o *FindParams) SetContext(ctx context.Context) {
   115  	o.Context = ctx
   116  }
   117  
   118  // WithHTTPClient adds the HTTPClient to the find params
   119  func (o *FindParams) WithHTTPClient(client *http.Client) *FindParams {
   120  	o.SetHTTPClient(client)
   121  	return o
   122  }
   123  
   124  // SetHTTPClient adds the HTTPClient to the find params
   125  func (o *FindParams) SetHTTPClient(client *http.Client) {
   126  	o.HTTPClient = client
   127  }
   128  
   129  // WithXRateLimit adds the xRateLimit to the find params
   130  func (o *FindParams) WithXRateLimit(xRateLimit int32) *FindParams {
   131  	o.SetXRateLimit(xRateLimit)
   132  	return o
   133  }
   134  
   135  // SetXRateLimit adds the xRateLimit to the find params
   136  func (o *FindParams) SetXRateLimit(xRateLimit int32) {
   137  	o.XRateLimit = xRateLimit
   138  }
   139  
   140  // WithLimit adds the limit to the find params
   141  func (o *FindParams) WithLimit(limit int32) *FindParams {
   142  	o.SetLimit(limit)
   143  	return o
   144  }
   145  
   146  // SetLimit adds the limit to the find params
   147  func (o *FindParams) SetLimit(limit int32) {
   148  	o.Limit = limit
   149  }
   150  
   151  // WithTags adds the tags to the find params
   152  func (o *FindParams) WithTags(tags []int32) *FindParams {
   153  	o.SetTags(tags)
   154  	return o
   155  }
   156  
   157  // SetTags adds the tags to the find params
   158  func (o *FindParams) SetTags(tags []int32) {
   159  	o.Tags = tags
   160  }
   161  
   162  // WriteToRequest writes these params to a swagger request
   163  func (o *FindParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
   164  
   165  	if err := r.SetTimeout(o.timeout); err != nil {
   166  		return err
   167  	}
   168  	var res []error
   169  
   170  	// header param X-Rate-Limit
   171  	if err := r.SetHeaderParam("X-Rate-Limit", swag.FormatInt32(o.XRateLimit)); err != nil {
   172  		return err
   173  	}
   174  
   175  	// form param limit
   176  	frLimit := o.Limit
   177  	fLimit := swag.FormatInt32(frLimit)
   178  	if err := r.SetFormParam("limit", fLimit); err != nil {
   179  		return err
   180  	}
   181  
   182  	if o.Tags != nil {
   183  
   184  		// binding items for tags
   185  		joinedTags := o.bindParamTags(reg)
   186  
   187  		// form array param tags
   188  		if err := r.SetFormParam("tags", joinedTags...); err != nil {
   189  			return err
   190  		}
   191  	}
   192  
   193  	if len(res) > 0 {
   194  		return errors.CompositeValidationError(res...)
   195  	}
   196  	return nil
   197  }
   198  
   199  // bindParamFind binds the parameter tags
   200  func (o *FindParams) bindParamTags(formats strfmt.Registry) []string {
   201  	tagsIR := o.Tags
   202  
   203  	var tagsIC []string
   204  	for _, tagsIIR := range tagsIR { // explode []int32
   205  
   206  		tagsIIV := swag.FormatInt32(tagsIIR) // int32 as string
   207  		tagsIC = append(tagsIC, tagsIIV)
   208  	}
   209  
   210  	// items.CollectionFormat: "multi"
   211  	tagsIS := swag.JoinByFormat(tagsIC, "multi")
   212  
   213  	return tagsIS
   214  }