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