github.com/kaisawind/go-swagger@v0.19.0/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  
    15  	strfmt "github.com/go-openapi/strfmt"
    16  )
    17  
    18  // NewLoginUserParams creates a new LoginUserParams object
    19  // no default values defined in 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  
    65  	if len(res) > 0 {
    66  		return errors.CompositeValidationError(res...)
    67  	}
    68  	return nil
    69  }
    70  
    71  // bindPassword binds and validates parameter Password from query.
    72  func (o *LoginUserParams) bindPassword(rawData []string, hasKey bool, formats strfmt.Registry) error {
    73  	var raw string
    74  	if len(rawData) > 0 {
    75  		raw = rawData[len(rawData)-1]
    76  	}
    77  
    78  	// Required: false
    79  	// AllowEmptyValue: false
    80  	if raw == "" { // empty values pass all other validations
    81  		return nil
    82  	}
    83  
    84  	o.Password = &raw
    85  
    86  	return nil
    87  }
    88  
    89  // bindUsername binds and validates parameter Username from query.
    90  func (o *LoginUserParams) 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: false
    97  	// AllowEmptyValue: false
    98  	if raw == "" { // empty values pass all other validations
    99  		return nil
   100  	}
   101  
   102  	o.Username = &raw
   103  
   104  	return nil
   105  }