github.com/djarvur/go-swagger@v0.18.0/examples/generated/restapi/operations/pet/delete_pet_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/middleware"
    13  	"github.com/go-openapi/swag"
    14  	"github.com/go-openapi/validate"
    15  
    16  	strfmt "github.com/go-openapi/strfmt"
    17  )
    18  
    19  // NewDeletePetParams creates a new DeletePetParams object
    20  // no default values defined in spec.
    21  func NewDeletePetParams() DeletePetParams {
    22  
    23  	return DeletePetParams{}
    24  }
    25  
    26  // DeletePetParams contains all the bound params for the delete pet operation
    27  // typically these are obtained from a http.Request
    28  //
    29  // swagger:parameters deletePet
    30  type DeletePetParams struct {
    31  
    32  	// HTTP Request Object
    33  	HTTPRequest *http.Request `json:"-"`
    34  
    35  	/*
    36  	  Required: true
    37  	  In: header
    38  	*/
    39  	APIKey string
    40  	/*Pet id to delete
    41  	  Required: true
    42  	  In: path
    43  	*/
    44  	PetID int64
    45  }
    46  
    47  // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
    48  // for simple values it will use straight method calls.
    49  //
    50  // To ensure default values, the struct must have been initialized with NewDeletePetParams() beforehand.
    51  func (o *DeletePetParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    52  	var res []error
    53  
    54  	o.HTTPRequest = r
    55  
    56  	if err := o.bindAPIKey(r.Header[http.CanonicalHeaderKey("api_key")], true, route.Formats); err != nil {
    57  		res = append(res, err)
    58  	}
    59  
    60  	rPetID, rhkPetID, _ := route.Params.GetOK("petId")
    61  	if err := o.bindPetID(rPetID, rhkPetID, route.Formats); err != nil {
    62  		res = append(res, err)
    63  	}
    64  
    65  	if len(res) > 0 {
    66  		return errors.CompositeValidationError(res...)
    67  	}
    68  	return nil
    69  }
    70  
    71  // bindAPIKey binds and validates parameter APIKey from header.
    72  func (o *DeletePetParams) bindAPIKey(rawData []string, hasKey bool, formats strfmt.Registry) error {
    73  	if !hasKey {
    74  		return errors.Required("api_key", "header")
    75  	}
    76  	var raw string
    77  	if len(rawData) > 0 {
    78  		raw = rawData[len(rawData)-1]
    79  	}
    80  
    81  	// Required: true
    82  
    83  	if err := validate.RequiredString("api_key", "header", raw); err != nil {
    84  		return err
    85  	}
    86  
    87  	o.APIKey = raw
    88  
    89  	return nil
    90  }
    91  
    92  // bindPetID binds and validates parameter PetID from path.
    93  func (o *DeletePetParams) bindPetID(rawData []string, hasKey bool, formats strfmt.Registry) error {
    94  	var raw string
    95  	if len(rawData) > 0 {
    96  		raw = rawData[len(rawData)-1]
    97  	}
    98  
    99  	// Required: true
   100  	// Parameter is provided by construction from the route
   101  
   102  	value, err := swag.ConvertInt64(raw)
   103  	if err != nil {
   104  		return errors.InvalidType("petId", "path", "int64", raw)
   105  	}
   106  	o.PetID = value
   107  
   108  	return nil
   109  }