github.com/kaisawind/go-swagger@v0.19.0/examples/generated/restapi/operations/user/update_user_parameters.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package user
     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  
    15  	strfmt "github.com/go-openapi/strfmt"
    16  
    17  	models "github.com/go-swagger/go-swagger/examples/generated/models"
    18  )
    19  
    20  // NewUpdateUserParams creates a new UpdateUserParams object
    21  // no default values defined in spec.
    22  func NewUpdateUserParams() UpdateUserParams {
    23  
    24  	return UpdateUserParams{}
    25  }
    26  
    27  // UpdateUserParams contains all the bound params for the update user operation
    28  // typically these are obtained from a http.Request
    29  //
    30  // swagger:parameters updateUser
    31  type UpdateUserParams struct {
    32  
    33  	// HTTP Request Object
    34  	HTTPRequest *http.Request `json:"-"`
    35  
    36  	/*Updated user object
    37  	  In: body
    38  	*/
    39  	Body *models.User
    40  	/*name that need to be deleted
    41  	  Required: true
    42  	  In: path
    43  	*/
    44  	Username string
    45  }
    46  
    47  // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
    48  // for simple values it will use straight method calls.
    49  //
    50  // To ensure default values, the struct must have been initialized with NewUpdateUserParams() beforehand.
    51  func (o *UpdateUserParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    52  	var res []error
    53  
    54  	o.HTTPRequest = r
    55  
    56  	if runtime.HasBody(r) {
    57  		defer r.Body.Close()
    58  		var body models.User
    59  		if err := route.Consumer.Consume(r.Body, &body); err != nil {
    60  			res = append(res, errors.NewParseError("body", "body", "", err))
    61  		} else {
    62  			// validate body object
    63  			if err := body.Validate(route.Formats); err != nil {
    64  				res = append(res, err)
    65  			}
    66  
    67  			if len(res) == 0 {
    68  				o.Body = &body
    69  			}
    70  		}
    71  	}
    72  	rUsername, rhkUsername, _ := route.Params.GetOK("username")
    73  	if err := o.bindUsername(rUsername, rhkUsername, route.Formats); err != nil {
    74  		res = append(res, err)
    75  	}
    76  
    77  	if len(res) > 0 {
    78  		return errors.CompositeValidationError(res...)
    79  	}
    80  	return nil
    81  }
    82  
    83  // bindUsername binds and validates parameter Username from path.
    84  func (o *UpdateUserParams) bindUsername(rawData []string, hasKey bool, formats strfmt.Registry) error {
    85  	var raw string
    86  	if len(rawData) > 0 {
    87  		raw = rawData[len(rawData)-1]
    88  	}
    89  
    90  	// Required: true
    91  	// Parameter is provided by construction from the route
    92  
    93  	o.Username = raw
    94  
    95  	return nil
    96  }