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