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