github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/generated/restapi/operations/pet/update_pet_with_form_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"
    13  	"github.com/go-openapi/runtime/middleware"
    14  	"github.com/go-openapi/strfmt"
    15  	"github.com/go-openapi/validate"
    16  )
    17  
    18  // UpdatePetWithFormMaxParseMemory sets the maximum size in bytes for
    19  // the multipart form parser for this operation.
    20  //
    21  // The default value is 32 MB.
    22  // The multipart parser stores up to this + 10MB.
    23  var UpdatePetWithFormMaxParseMemory int64 = 32 << 20
    24  
    25  // NewUpdatePetWithFormParams creates a new UpdatePetWithFormParams object
    26  //
    27  // There are no default values defined in the spec.
    28  func NewUpdatePetWithFormParams() UpdatePetWithFormParams {
    29  
    30  	return UpdatePetWithFormParams{}
    31  }
    32  
    33  // UpdatePetWithFormParams contains all the bound params for the update pet with form operation
    34  // typically these are obtained from a http.Request
    35  //
    36  // swagger:parameters updatePetWithForm
    37  type UpdatePetWithFormParams struct {
    38  
    39  	// HTTP Request Object
    40  	HTTPRequest *http.Request `json:"-"`
    41  
    42  	/*Updated name of the pet
    43  	  Required: true
    44  	  In: formData
    45  	*/
    46  	Name string
    47  	/*ID of pet that needs to be updated
    48  	  Required: true
    49  	  In: path
    50  	*/
    51  	PetID string
    52  	/*Updated status of the pet
    53  	  Required: true
    54  	  In: formData
    55  	*/
    56  	Status string
    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 NewUpdatePetWithFormParams() beforehand.
    63  func (o *UpdatePetWithFormParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    64  	var res []error
    65  
    66  	o.HTTPRequest = r
    67  
    68  	if err := r.ParseMultipartForm(UpdatePetWithFormMaxParseMemory); 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  	fdName, fdhkName, _ := fds.GetOK("name")
    78  	if err := o.bindName(fdName, fdhkName, route.Formats); err != nil {
    79  		res = append(res, err)
    80  	}
    81  
    82  	rPetID, rhkPetID, _ := route.Params.GetOK("petId")
    83  	if err := o.bindPetID(rPetID, rhkPetID, route.Formats); err != nil {
    84  		res = append(res, err)
    85  	}
    86  
    87  	fdStatus, fdhkStatus, _ := fds.GetOK("status")
    88  	if err := o.bindStatus(fdStatus, fdhkStatus, route.Formats); err != nil {
    89  		res = append(res, err)
    90  	}
    91  	if len(res) > 0 {
    92  		return errors.CompositeValidationError(res...)
    93  	}
    94  	return nil
    95  }
    96  
    97  // bindName binds and validates parameter Name from formData.
    98  func (o *UpdatePetWithFormParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error {
    99  	if !hasKey {
   100  		return errors.Required("name", "formData", rawData)
   101  	}
   102  	var raw string
   103  	if len(rawData) > 0 {
   104  		raw = rawData[len(rawData)-1]
   105  	}
   106  
   107  	// Required: true
   108  
   109  	if err := validate.RequiredString("name", "formData", raw); err != nil {
   110  		return err
   111  	}
   112  	o.Name = raw
   113  
   114  	return nil
   115  }
   116  
   117  // bindPetID binds and validates parameter PetID from path.
   118  func (o *UpdatePetWithFormParams) bindPetID(rawData []string, hasKey bool, formats strfmt.Registry) error {
   119  	var raw string
   120  	if len(rawData) > 0 {
   121  		raw = rawData[len(rawData)-1]
   122  	}
   123  
   124  	// Required: true
   125  	// Parameter is provided by construction from the route
   126  	o.PetID = raw
   127  
   128  	return nil
   129  }
   130  
   131  // bindStatus binds and validates parameter Status from formData.
   132  func (o *UpdatePetWithFormParams) bindStatus(rawData []string, hasKey bool, formats strfmt.Registry) error {
   133  	if !hasKey {
   134  		return errors.Required("status", "formData", rawData)
   135  	}
   136  	var raw string
   137  	if len(rawData) > 0 {
   138  		raw = rawData[len(rawData)-1]
   139  	}
   140  
   141  	// Required: true
   142  
   143  	if err := validate.RequiredString("status", "formData", raw); err != nil {
   144  		return err
   145  	}
   146  	o.Status = raw
   147  
   148  	return nil
   149  }