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