github.com/circl-dev/go-swagger@v0.31.0/examples/task-tracker/restapi/operations/tasks/upload_task_file_parameters.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package tasks 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/strfmt" 15 "github.com/go-openapi/swag" 16 "github.com/circl-dev/runtime" 17 "github.com/circl-dev/runtime/middleware" 18 ) 19 20 // UploadTaskFileMaxParseMemory 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 UploadTaskFileMaxParseMemory int64 = 32 << 20 26 27 // NewUploadTaskFileParams creates a new UploadTaskFileParams object 28 // 29 // There are no default values defined in the spec. 30 func NewUploadTaskFileParams() UploadTaskFileParams { 31 32 return UploadTaskFileParams{} 33 } 34 35 // UploadTaskFileParams contains all the bound params for the upload task file operation 36 // typically these are obtained from a http.Request 37 // 38 // swagger:parameters uploadTaskFile 39 type UploadTaskFileParams struct { 40 41 // HTTP Request Object 42 HTTPRequest *http.Request `json:"-"` 43 44 /*Extra information describing the file 45 In: formData 46 */ 47 Description *string 48 /*The file to upload 49 In: formData 50 */ 51 File io.ReadCloser 52 /*The id of the item 53 Required: true 54 In: path 55 */ 56 ID 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 NewUploadTaskFileParams() beforehand. 63 func (o *UploadTaskFileParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { 64 var res []error 65 66 o.HTTPRequest = r 67 68 if err := r.ParseMultipartForm(UploadTaskFileMaxParseMemory); 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 fdDescription, fdhkDescription, _ := fds.GetOK("description") 78 if err := o.bindDescription(fdDescription, fdhkDescription, 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 rID, rhkID, _ := route.Params.GetOK("id") 94 if err := o.bindID(rID, rhkID, 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 // bindDescription binds and validates parameter Description from formData. 104 func (o *UploadTaskFileParams) bindDescription(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.Description = &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 *UploadTaskFileParams) bindFile(file multipart.File, header *multipart.FileHeader) error { 124 return nil 125 } 126 127 // bindID binds and validates parameter ID from path. 128 func (o *UploadTaskFileParams) bindID(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("id", "path", "int64", raw) 140 } 141 o.ID = value 142 143 return nil 144 }