github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/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/strfmt"
    14  	"github.com/go-openapi/swag"
    15  	"github.com/go-openapi/validate"
    16  )
    17  
    18  // NewDeletePetParams creates a new DeletePetParams object
    19  //
    20  // There are no default values defined in the 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  	if len(res) > 0 {
    65  		return errors.CompositeValidationError(res...)
    66  	}
    67  	return nil
    68  }
    69  
    70  // bindAPIKey binds and validates parameter APIKey from header.
    71  func (o *DeletePetParams) bindAPIKey(rawData []string, hasKey bool, formats strfmt.Registry) error {
    72  	if !hasKey {
    73  		return errors.Required("api_key", "header", rawData)
    74  	}
    75  	var raw string
    76  	if len(rawData) > 0 {
    77  		raw = rawData[len(rawData)-1]
    78  	}
    79  
    80  	// Required: true
    81  
    82  	if err := validate.RequiredString("api_key", "header", raw); err != nil {
    83  		return err
    84  	}
    85  	o.APIKey = raw
    86  
    87  	return nil
    88  }
    89  
    90  // bindPetID binds and validates parameter PetID from path.
    91  func (o *DeletePetParams) bindPetID(rawData []string, hasKey bool, formats strfmt.Registry) error {
    92  	var raw string
    93  	if len(rawData) > 0 {
    94  		raw = rawData[len(rawData)-1]
    95  	}
    96  
    97  	// Required: true
    98  	// Parameter is provided by construction from the route
    99  
   100  	value, err := swag.ConvertInt64(raw)
   101  	if err != nil {
   102  		return errors.InvalidType("petId", "path", "int64", raw)
   103  	}
   104  	o.PetID = value
   105  
   106  	return nil
   107  }