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