github.com/circl-dev/go-swagger@v0.31.0/examples/auto-configure/restapi/operations/todos/find_todos_parameters.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package todos
     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/strfmt"
    13  	"github.com/go-openapi/swag"
    14  	"github.com/circl-dev/runtime"
    15  	"github.com/circl-dev/runtime/middleware"
    16  )
    17  
    18  // NewFindTodosParams creates a new FindTodosParams object
    19  // with the default values initialized.
    20  func NewFindTodosParams() FindTodosParams {
    21  
    22  	var (
    23  		// initialize parameters with default values
    24  
    25  		limitDefault = int32(20)
    26  	)
    27  
    28  	return FindTodosParams{
    29  		Limit: &limitDefault,
    30  	}
    31  }
    32  
    33  // FindTodosParams contains all the bound params for the find todos operation
    34  // typically these are obtained from a http.Request
    35  //
    36  // swagger:parameters findTodos
    37  type FindTodosParams struct {
    38  
    39  	// HTTP Request Object
    40  	HTTPRequest *http.Request `json:"-"`
    41  
    42  	/*
    43  	  In: query
    44  	  Default: 20
    45  	*/
    46  	Limit *int32
    47  	/*
    48  	  In: query
    49  	*/
    50  	Since *int64
    51  }
    52  
    53  // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
    54  // for simple values it will use straight method calls.
    55  //
    56  // To ensure default values, the struct must have been initialized with NewFindTodosParams() beforehand.
    57  func (o *FindTodosParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    58  	var res []error
    59  
    60  	o.HTTPRequest = r
    61  
    62  	qs := runtime.Values(r.URL.Query())
    63  
    64  	qLimit, qhkLimit, _ := qs.GetOK("limit")
    65  	if err := o.bindLimit(qLimit, qhkLimit, route.Formats); err != nil {
    66  		res = append(res, err)
    67  	}
    68  
    69  	qSince, qhkSince, _ := qs.GetOK("since")
    70  	if err := o.bindSince(qSince, qhkSince, route.Formats); err != nil {
    71  		res = append(res, err)
    72  	}
    73  	if len(res) > 0 {
    74  		return errors.CompositeValidationError(res...)
    75  	}
    76  	return nil
    77  }
    78  
    79  // bindLimit binds and validates parameter Limit from query.
    80  func (o *FindTodosParams) bindLimit(rawData []string, hasKey bool, formats strfmt.Registry) error {
    81  	var raw string
    82  	if len(rawData) > 0 {
    83  		raw = rawData[len(rawData)-1]
    84  	}
    85  
    86  	// Required: false
    87  	// AllowEmptyValue: false
    88  
    89  	if raw == "" { // empty values pass all other validations
    90  		// Default values have been previously initialized by NewFindTodosParams()
    91  		return nil
    92  	}
    93  
    94  	value, err := swag.ConvertInt32(raw)
    95  	if err != nil {
    96  		return errors.InvalidType("limit", "query", "int32", raw)
    97  	}
    98  	o.Limit = &value
    99  
   100  	return nil
   101  }
   102  
   103  // bindSince binds and validates parameter Since from query.
   104  func (o *FindTodosParams) bindSince(rawData []string, hasKey bool, formats strfmt.Registry) error {
   105  	var raw string
   106  	if len(rawData) > 0 {
   107  		raw = rawData[len(rawData)-1]
   108  	}
   109  
   110  	// Required: false
   111  	// AllowEmptyValue: false
   112  
   113  	if raw == "" { // empty values pass all other validations
   114  		return nil
   115  	}
   116  
   117  	value, err := swag.ConvertInt64(raw)
   118  	if err != nil {
   119  		return errors.InvalidType("since", "query", "int64", raw)
   120  	}
   121  	o.Since = &value
   122  
   123  	return nil
   124  }