github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/generated/restapi/operations/pet/find_pets_by_status_parameters.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package pet
     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  	"net/http"
    10  
    11  	"github.com/go-openapi/errors"
    12  	"github.com/go-openapi/runtime"
    13  	"github.com/go-openapi/runtime/middleware"
    14  	"github.com/go-openapi/strfmt"
    15  )
    16  
    17  // NewFindPetsByStatusParams creates a new FindPetsByStatusParams object
    18  //
    19  // There are no default values defined in the spec.
    20  func NewFindPetsByStatusParams() FindPetsByStatusParams {
    21  
    22  	return FindPetsByStatusParams{}
    23  }
    24  
    25  // FindPetsByStatusParams contains all the bound params for the find pets by status operation
    26  // typically these are obtained from a http.Request
    27  //
    28  // swagger:parameters findPetsByStatus
    29  type FindPetsByStatusParams struct {
    30  
    31  	// HTTP Request Object
    32  	HTTPRequest *http.Request `json:"-"`
    33  
    34  	/*Status values that need to be considered for filter
    35  	  In: query
    36  	  Collection Format: multi
    37  	*/
    38  	Status []string
    39  }
    40  
    41  // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
    42  // for simple values it will use straight method calls.
    43  //
    44  // To ensure default values, the struct must have been initialized with NewFindPetsByStatusParams() beforehand.
    45  func (o *FindPetsByStatusParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    46  	var res []error
    47  
    48  	o.HTTPRequest = r
    49  
    50  	qs := runtime.Values(r.URL.Query())
    51  
    52  	qStatus, qhkStatus, _ := qs.GetOK("status")
    53  	if err := o.bindStatus(qStatus, qhkStatus, route.Formats); err != nil {
    54  		res = append(res, err)
    55  	}
    56  	if len(res) > 0 {
    57  		return errors.CompositeValidationError(res...)
    58  	}
    59  	return nil
    60  }
    61  
    62  // bindStatus binds and validates array parameter Status from query.
    63  //
    64  // Arrays are parsed according to CollectionFormat: "multi" (defaults to "csv" when empty).
    65  func (o *FindPetsByStatusParams) bindStatus(rawData []string, hasKey bool, formats strfmt.Registry) error {
    66  	// CollectionFormat: multi
    67  	statusIC := rawData
    68  	if len(statusIC) == 0 {
    69  		return nil
    70  	}
    71  
    72  	var statusIR []string
    73  	for _, statusIV := range statusIC {
    74  		statusI := statusIV
    75  
    76  		statusIR = append(statusIR, statusI)
    77  	}
    78  
    79  	o.Status = statusIR
    80  
    81  	return nil
    82  }