github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/examples/generated/restapi/operations/user/login_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  )
    16  
    17  // NewLoginUserParams creates a new LoginUserParams object
    18  //
    19  // There are no default values defined in the spec.
    20  func NewLoginUserParams() LoginUserParams {
    21  
    22  	return LoginUserParams{}
    23  }
    24  
    25  // LoginUserParams contains all the bound params for the login user operation
    26  // typically these are obtained from a http.Request
    27  //
    28  // swagger:parameters loginUser
    29  type LoginUserParams struct {
    30  
    31  	// HTTP Request Object
    32  	HTTPRequest *http.Request `json:"-"`
    33  
    34  	/*The password for login in clear text
    35  	  In: query
    36  	*/
    37  	Password *string
    38  	/*The user name for login
    39  	  In: query
    40  	*/
    41  	Username *string
    42  }
    43  
    44  // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
    45  // for simple values it will use straight method calls.
    46  //
    47  // To ensure default values, the struct must have been initialized with NewLoginUserParams() beforehand.
    48  func (o *LoginUserParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    49  	var res []error
    50  
    51  	o.HTTPRequest = r
    52  
    53  	qs := runtime.Values(r.URL.Query())
    54  
    55  	qPassword, qhkPassword, _ := qs.GetOK("password")
    56  	if err := o.bindPassword(qPassword, qhkPassword, route.Formats); err != nil {
    57  		res = append(res, err)
    58  	}
    59  
    60  	qUsername, qhkUsername, _ := qs.GetOK("username")
    61  	if err := o.bindUsername(qUsername, qhkUsername, route.Formats); err != nil {
    62  		res = append(res, err)
    63  	}
    64  	if len(res) > 0 {
    65  		return errors.CompositeValidationError(res...)
    66  	}
    67  	return nil
    68  }
    69  
    70  // bindPassword binds and validates parameter Password from query.
    71  func (o *LoginUserParams) bindPassword(rawData []string, hasKey bool, formats strfmt.Registry) error {
    72  	var raw string
    73  	if len(rawData) > 0 {
    74  		raw = rawData[len(rawData)-1]
    75  	}
    76  
    77  	// Required: false
    78  	// AllowEmptyValue: false
    79  
    80  	if raw == "" { // empty values pass all other validations
    81  		return nil
    82  	}
    83  	o.Password = &raw
    84  
    85  	return nil
    86  }
    87  
    88  // bindUsername binds and validates parameter Username from query.
    89  func (o *LoginUserParams) bindUsername(rawData []string, hasKey bool, formats strfmt.Registry) error {
    90  	var raw string
    91  	if len(rawData) > 0 {
    92  		raw = rawData[len(rawData)-1]
    93  	}
    94  
    95  	// Required: false
    96  	// AllowEmptyValue: false
    97  
    98  	if raw == "" { // empty values pass all other validations
    99  		return nil
   100  	}
   101  	o.Username = &raw
   102  
   103  	return nil
   104  }