github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/contributed-templates/stratoscale/restapi/operations/pet/pet_upload_image_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 "io" 10 "mime/multipart" 11 "net/http" 12 13 "github.com/go-openapi/errors" 14 "github.com/go-openapi/runtime" 15 "github.com/go-openapi/runtime/middleware" 16 "github.com/go-openapi/strfmt" 17 "github.com/go-openapi/swag" 18 ) 19 20 // PetUploadImageMaxParseMemory sets the maximum size in bytes for 21 // the multipart form parser for this operation. 22 // 23 // The default value is 32 MB. 24 // The multipart parser stores up to this + 10MB. 25 var PetUploadImageMaxParseMemory int64 = 32 << 20 26 27 // NewPetUploadImageParams creates a new PetUploadImageParams object 28 // 29 // There are no default values defined in the spec. 30 func NewPetUploadImageParams() PetUploadImageParams { 31 32 return PetUploadImageParams{} 33 } 34 35 // PetUploadImageParams contains all the bound params for the pet upload image operation 36 // typically these are obtained from a http.Request 37 // 38 // swagger:parameters PetUploadImage 39 type PetUploadImageParams struct { 40 41 // HTTP Request Object 42 HTTPRequest *http.Request `json:"-"` 43 44 /*Additional data to pass to server 45 In: formData 46 */ 47 AdditionalMetadata *string 48 /*file to upload 49 In: formData 50 */ 51 File io.ReadCloser 52 /*ID of pet to update 53 Required: true 54 In: path 55 */ 56 PetID int64 57 } 58 59 // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface 60 // for simple values it will use straight method calls. 61 // 62 // To ensure default values, the struct must have been initialized with NewPetUploadImageParams() beforehand. 63 func (o *PetUploadImageParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { 64 var res []error 65 66 o.HTTPRequest = r 67 68 if err := r.ParseMultipartForm(PetUploadImageMaxParseMemory); err != nil { 69 if err != http.ErrNotMultipart { 70 return errors.New(400, "%v", err) 71 } else if err := r.ParseForm(); err != nil { 72 return errors.New(400, "%v", err) 73 } 74 } 75 fds := runtime.Values(r.Form) 76 77 fdAdditionalMetadata, fdhkAdditionalMetadata, _ := fds.GetOK("additionalMetadata") 78 if err := o.bindAdditionalMetadata(fdAdditionalMetadata, fdhkAdditionalMetadata, route.Formats); err != nil { 79 res = append(res, err) 80 } 81 82 file, fileHeader, err := r.FormFile("file") 83 if err != nil && err != http.ErrMissingFile { 84 res = append(res, errors.New(400, "reading file %q failed: %v", "file", err)) 85 } else if err == http.ErrMissingFile { 86 // no-op for missing but optional file parameter 87 } else if err := o.bindFile(file, fileHeader); err != nil { 88 res = append(res, err) 89 } else { 90 o.File = &runtime.File{Data: file, Header: fileHeader} 91 } 92 93 rPetID, rhkPetID, _ := route.Params.GetOK("petId") 94 if err := o.bindPetID(rPetID, rhkPetID, route.Formats); err != nil { 95 res = append(res, err) 96 } 97 if len(res) > 0 { 98 return errors.CompositeValidationError(res...) 99 } 100 return nil 101 } 102 103 // bindAdditionalMetadata binds and validates parameter AdditionalMetadata from formData. 104 func (o *PetUploadImageParams) bindAdditionalMetadata(rawData []string, hasKey bool, formats strfmt.Registry) error { 105 var raw string 106 if len(rawData) > 0 { 107 raw = rawData[len(rawData)-1] 108 } 109 110 // Required: false 111 112 if raw == "" { // empty values pass all other validations 113 return nil 114 } 115 o.AdditionalMetadata = &raw 116 117 return nil 118 } 119 120 // bindFile binds file parameter File. 121 // 122 // The only supported validations on files are MinLength and MaxLength 123 func (o *PetUploadImageParams) bindFile(file multipart.File, header *multipart.FileHeader) error { 124 return nil 125 } 126 127 // bindPetID binds and validates parameter PetID from path. 128 func (o *PetUploadImageParams) bindPetID(rawData []string, hasKey bool, formats strfmt.Registry) error { 129 var raw string 130 if len(rawData) > 0 { 131 raw = rawData[len(rawData)-1] 132 } 133 134 // Required: true 135 // Parameter is provided by construction from the route 136 137 value, err := swag.ConvertInt64(raw) 138 if err != nil { 139 return errors.InvalidType("petId", "path", "int64", raw) 140 } 141 o.PetID = value 142 143 return nil 144 }