github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/generated/restapi/operations/pet/get_pet_by_id_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  )
    16  
    17  // NewGetPetByIDParams creates a new GetPetByIDParams object
    18  //
    19  // There are no default values defined in the spec.
    20  func NewGetPetByIDParams() GetPetByIDParams {
    21  
    22  	return GetPetByIDParams{}
    23  }
    24  
    25  // GetPetByIDParams contains all the bound params for the get pet by Id operation
    26  // typically these are obtained from a http.Request
    27  //
    28  // swagger:parameters getPetById
    29  type GetPetByIDParams struct {
    30  
    31  	// HTTP Request Object
    32  	HTTPRequest *http.Request `json:"-"`
    33  
    34  	/*ID of pet that needs to be fetched
    35  	  Required: true
    36  	  In: path
    37  	*/
    38  	PetID int64
    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 NewGetPetByIDParams() beforehand.
    45  func (o *GetPetByIDParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    46  	var res []error
    47  
    48  	o.HTTPRequest = r
    49  
    50  	rPetID, rhkPetID, _ := route.Params.GetOK("petId")
    51  	if err := o.bindPetID(rPetID, rhkPetID, route.Formats); err != nil {
    52  		res = append(res, err)
    53  	}
    54  	if len(res) > 0 {
    55  		return errors.CompositeValidationError(res...)
    56  	}
    57  	return nil
    58  }
    59  
    60  // bindPetID binds and validates parameter PetID from path.
    61  func (o *GetPetByIDParams) bindPetID(rawData []string, hasKey bool, formats strfmt.Registry) error {
    62  	var raw string
    63  	if len(rawData) > 0 {
    64  		raw = rawData[len(rawData)-1]
    65  	}
    66  
    67  	// Required: true
    68  	// Parameter is provided by construction from the route
    69  
    70  	value, err := swag.ConvertInt64(raw)
    71  	if err != nil {
    72  		return errors.InvalidType("petId", "path", "int64", raw)
    73  	}
    74  	o.PetID = value
    75  
    76  	return nil
    77  }