github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/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  /*
    57  FindParams contains all the parameters to send to the API endpoint
    58  
    59  	for the find operation.
    60  
    61  	Typically these are written to a http.Request.
    62  */
    63  type FindParams struct {
    64  
    65  	// XRateLimit.
    66  	//
    67  	// Format: int32
    68  	XRateLimit int32
    69  
    70  	// Limit.
    71  	//
    72  	// Format: int32
    73  	Limit int32
    74  
    75  	// Tags.
    76  	Tags []int32
    77  
    78  	timeout    time.Duration
    79  	Context    context.Context
    80  	HTTPClient *http.Client
    81  }
    82  
    83  // WithDefaults hydrates default values in the find params (not the query body).
    84  //
    85  // All values with no default are reset to their zero value.
    86  func (o *FindParams) WithDefaults() *FindParams {
    87  	o.SetDefaults()
    88  	return o
    89  }
    90  
    91  // SetDefaults hydrates default values in the find params (not the query body).
    92  //
    93  // All values with no default are reset to their zero value.
    94  func (o *FindParams) SetDefaults() {
    95  	// no default values defined for this parameter
    96  }
    97  
    98  // WithTimeout adds the timeout to the find params
    99  func (o *FindParams) WithTimeout(timeout time.Duration) *FindParams {
   100  	o.SetTimeout(timeout)
   101  	return o
   102  }
   103  
   104  // SetTimeout adds the timeout to the find params
   105  func (o *FindParams) SetTimeout(timeout time.Duration) {
   106  	o.timeout = timeout
   107  }
   108  
   109  // WithContext adds the context to the find params
   110  func (o *FindParams) WithContext(ctx context.Context) *FindParams {
   111  	o.SetContext(ctx)
   112  	return o
   113  }
   114  
   115  // SetContext adds the context to the find params
   116  func (o *FindParams) SetContext(ctx context.Context) {
   117  	o.Context = ctx
   118  }
   119  
   120  // WithHTTPClient adds the HTTPClient to the find params
   121  func (o *FindParams) WithHTTPClient(client *http.Client) *FindParams {
   122  	o.SetHTTPClient(client)
   123  	return o
   124  }
   125  
   126  // SetHTTPClient adds the HTTPClient to the find params
   127  func (o *FindParams) SetHTTPClient(client *http.Client) {
   128  	o.HTTPClient = client
   129  }
   130  
   131  // WithXRateLimit adds the xRateLimit to the find params
   132  func (o *FindParams) WithXRateLimit(xRateLimit int32) *FindParams {
   133  	o.SetXRateLimit(xRateLimit)
   134  	return o
   135  }
   136  
   137  // SetXRateLimit adds the xRateLimit to the find params
   138  func (o *FindParams) SetXRateLimit(xRateLimit int32) {
   139  	o.XRateLimit = xRateLimit
   140  }
   141  
   142  // WithLimit adds the limit to the find params
   143  func (o *FindParams) WithLimit(limit int32) *FindParams {
   144  	o.SetLimit(limit)
   145  	return o
   146  }
   147  
   148  // SetLimit adds the limit to the find params
   149  func (o *FindParams) SetLimit(limit int32) {
   150  	o.Limit = limit
   151  }
   152  
   153  // WithTags adds the tags to the find params
   154  func (o *FindParams) WithTags(tags []int32) *FindParams {
   155  	o.SetTags(tags)
   156  	return o
   157  }
   158  
   159  // SetTags adds the tags to the find params
   160  func (o *FindParams) SetTags(tags []int32) {
   161  	o.Tags = tags
   162  }
   163  
   164  // WriteToRequest writes these params to a swagger request
   165  func (o *FindParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error {
   166  
   167  	if err := r.SetTimeout(o.timeout); err != nil {
   168  		return err
   169  	}
   170  	var res []error
   171  
   172  	// header param X-Rate-Limit
   173  	if err := r.SetHeaderParam("X-Rate-Limit", swag.FormatInt32(o.XRateLimit)); err != nil {
   174  		return err
   175  	}
   176  
   177  	// form param limit
   178  	frLimit := o.Limit
   179  	fLimit := swag.FormatInt32(frLimit)
   180  	if err := r.SetFormParam("limit", fLimit); err != nil {
   181  		return err
   182  	}
   183  
   184  	if o.Tags != nil {
   185  
   186  		// binding items for tags
   187  		joinedTags := o.bindParamTags(reg)
   188  
   189  		// form array param tags
   190  		if err := r.SetFormParam("tags", joinedTags...); err != nil {
   191  			return err
   192  		}
   193  	}
   194  
   195  	if len(res) > 0 {
   196  		return errors.CompositeValidationError(res...)
   197  	}
   198  	return nil
   199  }
   200  
   201  // bindParamFind binds the parameter tags
   202  func (o *FindParams) bindParamTags(formats strfmt.Registry) []string {
   203  	tagsIR := o.Tags
   204  
   205  	var tagsIC []string
   206  	for _, tagsIIR := range tagsIR { // explode []int32
   207  
   208  		tagsIIV := swag.FormatInt32(tagsIIR) // int32 as string
   209  		tagsIC = append(tagsIC, tagsIIV)
   210  	}
   211  
   212  	// items.CollectionFormat: "multi"
   213  	tagsIS := swag.JoinByFormat(tagsIC, "multi")
   214  
   215  	return tagsIS
   216  }