github.com/circl-dev/go-swagger@v0.31.0/examples/task-tracker/restapi/operations/tasks/get_task_comments_parameters.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package tasks
     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  	"github.com/circl-dev/validate"
    17  )
    18  
    19  // NewGetTaskCommentsParams creates a new GetTaskCommentsParams object
    20  // with the default values initialized.
    21  func NewGetTaskCommentsParams() GetTaskCommentsParams {
    22  
    23  	var (
    24  		// initialize parameters with default values
    25  
    26  		pageSizeDefault = int32(20)
    27  	)
    28  
    29  	return GetTaskCommentsParams{
    30  		PageSize: &pageSizeDefault,
    31  	}
    32  }
    33  
    34  // GetTaskCommentsParams contains all the bound params for the get task comments operation
    35  // typically these are obtained from a http.Request
    36  //
    37  // swagger:parameters getTaskComments
    38  type GetTaskCommentsParams struct {
    39  
    40  	// HTTP Request Object
    41  	HTTPRequest *http.Request `json:"-"`
    42  
    43  	/*The id of the item
    44  	  Required: true
    45  	  In: path
    46  	*/
    47  	ID int64
    48  	/*Amount of items to return in a single page
    49  	  In: query
    50  	  Default: 20
    51  	*/
    52  	PageSize *int32
    53  	/*The created time of the oldest seen comment
    54  	  In: query
    55  	*/
    56  	Since *strfmt.DateTime
    57  }
    58  
    59  // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
    60  // for simple values it will use straight method calls.
    61  //
    62  // To ensure default values, the struct must have been initialized with NewGetTaskCommentsParams() beforehand.
    63  func (o *GetTaskCommentsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    64  	var res []error
    65  
    66  	o.HTTPRequest = r
    67  
    68  	qs := runtime.Values(r.URL.Query())
    69  
    70  	rID, rhkID, _ := route.Params.GetOK("id")
    71  	if err := o.bindID(rID, rhkID, route.Formats); err != nil {
    72  		res = append(res, err)
    73  	}
    74  
    75  	qPageSize, qhkPageSize, _ := qs.GetOK("pageSize")
    76  	if err := o.bindPageSize(qPageSize, qhkPageSize, route.Formats); err != nil {
    77  		res = append(res, err)
    78  	}
    79  
    80  	qSince, qhkSince, _ := qs.GetOK("since")
    81  	if err := o.bindSince(qSince, qhkSince, route.Formats); err != nil {
    82  		res = append(res, err)
    83  	}
    84  	if len(res) > 0 {
    85  		return errors.CompositeValidationError(res...)
    86  	}
    87  	return nil
    88  }
    89  
    90  // bindID binds and validates parameter ID from path.
    91  func (o *GetTaskCommentsParams) bindID(rawData []string, hasKey bool, formats strfmt.Registry) error {
    92  	var raw string
    93  	if len(rawData) > 0 {
    94  		raw = rawData[len(rawData)-1]
    95  	}
    96  
    97  	// Required: true
    98  	// Parameter is provided by construction from the route
    99  
   100  	value, err := swag.ConvertInt64(raw)
   101  	if err != nil {
   102  		return errors.InvalidType("id", "path", "int64", raw)
   103  	}
   104  	o.ID = value
   105  
   106  	return nil
   107  }
   108  
   109  // bindPageSize binds and validates parameter PageSize from query.
   110  func (o *GetTaskCommentsParams) bindPageSize(rawData []string, hasKey bool, formats strfmt.Registry) error {
   111  	var raw string
   112  	if len(rawData) > 0 {
   113  		raw = rawData[len(rawData)-1]
   114  	}
   115  
   116  	// Required: false
   117  	// AllowEmptyValue: false
   118  
   119  	if raw == "" { // empty values pass all other validations
   120  		// Default values have been previously initialized by NewGetTaskCommentsParams()
   121  		return nil
   122  	}
   123  
   124  	value, err := swag.ConvertInt32(raw)
   125  	if err != nil {
   126  		return errors.InvalidType("pageSize", "query", "int32", raw)
   127  	}
   128  	o.PageSize = &value
   129  
   130  	return nil
   131  }
   132  
   133  // bindSince binds and validates parameter Since from query.
   134  func (o *GetTaskCommentsParams) bindSince(rawData []string, hasKey bool, formats strfmt.Registry) error {
   135  	var raw string
   136  	if len(rawData) > 0 {
   137  		raw = rawData[len(rawData)-1]
   138  	}
   139  
   140  	// Required: false
   141  	// AllowEmptyValue: false
   142  
   143  	if raw == "" { // empty values pass all other validations
   144  		return nil
   145  	}
   146  
   147  	// Format: date-time
   148  	value, err := formats.Parse("date-time", raw)
   149  	if err != nil {
   150  		return errors.InvalidType("since", "query", "strfmt.DateTime", raw)
   151  	}
   152  	o.Since = (value.(*strfmt.DateTime))
   153  
   154  	if err := o.validateSince(formats); err != nil {
   155  		return err
   156  	}
   157  
   158  	return nil
   159  }
   160  
   161  // validateSince carries on validations for parameter Since
   162  func (o *GetTaskCommentsParams) validateSince(formats strfmt.Registry) error {
   163  
   164  	if err := validate.FormatOf("since", "query", "date-time", o.Since.String(), formats); err != nil {
   165  		return err
   166  	}
   167  	return nil
   168  }