github.com/Percona-Lab/go-swagger@v0.19.0/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/validate"
    16  
    17  	strfmt "github.com/go-openapi/strfmt"
    18  )
    19  
    20  // NewPetListParams creates a new PetListParams object
    21  // no default values defined in 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  
    60  	if len(res) > 0 {
    61  		return errors.CompositeValidationError(res...)
    62  	}
    63  	return nil
    64  }
    65  
    66  // bindStatus binds and validates array parameter Status from query.
    67  //
    68  // Arrays are parsed according to CollectionFormat: "multi" (defaults to "csv" when empty).
    69  func (o *PetListParams) bindStatus(rawData []string, hasKey bool, formats strfmt.Registry) error {
    70  	if !hasKey {
    71  		return errors.Required("status", "query")
    72  	}
    73  
    74  	// CollectionFormat: multi
    75  	statusIC := rawData
    76  
    77  	if len(statusIC) == 0 {
    78  		return errors.Required("status", "query")
    79  	}
    80  
    81  	var statusIR []string
    82  	for i, statusIV := range statusIC {
    83  		statusI := statusIV
    84  
    85  		if err := validate.Enum(fmt.Sprintf("%s.%v", "status", i), "query", statusI, []interface{}{"available", "pending", "sold"}); err != nil {
    86  			return err
    87  		}
    88  
    89  		statusIR = append(statusIR, statusI)
    90  	}
    91  
    92  	o.Status = statusIR
    93  
    94  	return nil
    95  }