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