github.com/djarvur/go-swagger@v0.18.0/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  
    15  	strfmt "github.com/go-openapi/strfmt"
    16  )
    17  
    18  // NewFindPetsByStatusParams creates a new FindPetsByStatusParams object
    19  // no default values defined in 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  
    57  	if len(res) > 0 {
    58  		return errors.CompositeValidationError(res...)
    59  	}
    60  	return nil
    61  }
    62  
    63  // bindStatus binds and validates array parameter Status from query.
    64  //
    65  // Arrays are parsed according to CollectionFormat: "multi" (defaults to "csv" when empty).
    66  func (o *FindPetsByStatusParams) bindStatus(rawData []string, hasKey bool, formats strfmt.Registry) error {
    67  
    68  	// CollectionFormat: multi
    69  	statusIC := rawData
    70  
    71  	if len(statusIC) == 0 {
    72  		return nil
    73  	}
    74  
    75  	var statusIR []string
    76  	for _, statusIV := range statusIC {
    77  		statusI := statusIV
    78  
    79  		statusIR = append(statusIR, statusI)
    80  	}
    81  
    82  	o.Status = statusIR
    83  
    84  	return nil
    85  }