github.com/dirkm/go-swagger@v0.19.0/examples/task-tracker/restapi/operations/tasks/list_tasks_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  	"fmt"
    10  	"net/http"
    11  
    12  	"github.com/go-openapi/errors"
    13  	"github.com/go-openapi/runtime"
    14  	"github.com/go-openapi/runtime/middleware"
    15  	"github.com/go-openapi/swag"
    16  	"github.com/go-openapi/validate"
    17  
    18  	strfmt "github.com/go-openapi/strfmt"
    19  )
    20  
    21  // NewListTasksParams creates a new ListTasksParams object
    22  // with the default values initialized.
    23  func NewListTasksParams() ListTasksParams {
    24  
    25  	var (
    26  		// initialize parameters with default values
    27  
    28  		pageSizeDefault = int32(20)
    29  	)
    30  
    31  	return ListTasksParams{
    32  		PageSize: &pageSizeDefault,
    33  	}
    34  }
    35  
    36  // ListTasksParams contains all the bound params for the list tasks operation
    37  // typically these are obtained from a http.Request
    38  //
    39  // swagger:parameters listTasks
    40  type ListTasksParams struct {
    41  
    42  	// HTTP Request Object
    43  	HTTPRequest *http.Request `json:"-"`
    44  
    45  	/*Amount of items to return in a single page
    46  	  In: query
    47  	  Default: 20
    48  	*/
    49  	PageSize *int32
    50  	/*The last id that was seen.
    51  	  In: query
    52  	*/
    53  	SinceID *int64
    54  	/*the status to filter by
    55  	  Unique: true
    56  	  In: query
    57  	  Collection Format: pipes
    58  	*/
    59  	Status []string
    60  	/*the tags to filter by
    61  	  Unique: true
    62  	  In: query
    63  	*/
    64  	Tags []string
    65  }
    66  
    67  // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
    68  // for simple values it will use straight method calls.
    69  //
    70  // To ensure default values, the struct must have been initialized with NewListTasksParams() beforehand.
    71  func (o *ListTasksParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    72  	var res []error
    73  
    74  	o.HTTPRequest = r
    75  
    76  	qs := runtime.Values(r.URL.Query())
    77  
    78  	qPageSize, qhkPageSize, _ := qs.GetOK("pageSize")
    79  	if err := o.bindPageSize(qPageSize, qhkPageSize, route.Formats); err != nil {
    80  		res = append(res, err)
    81  	}
    82  
    83  	qSinceID, qhkSinceID, _ := qs.GetOK("sinceId")
    84  	if err := o.bindSinceID(qSinceID, qhkSinceID, route.Formats); err != nil {
    85  		res = append(res, err)
    86  	}
    87  
    88  	qStatus, qhkStatus, _ := qs.GetOK("status")
    89  	if err := o.bindStatus(qStatus, qhkStatus, route.Formats); err != nil {
    90  		res = append(res, err)
    91  	}
    92  
    93  	qTags, qhkTags, _ := qs.GetOK("tags")
    94  	if err := o.bindTags(qTags, qhkTags, route.Formats); err != nil {
    95  		res = append(res, err)
    96  	}
    97  
    98  	if len(res) > 0 {
    99  		return errors.CompositeValidationError(res...)
   100  	}
   101  	return nil
   102  }
   103  
   104  // bindPageSize binds and validates parameter PageSize from query.
   105  func (o *ListTasksParams) bindPageSize(rawData []string, hasKey bool, formats strfmt.Registry) error {
   106  	var raw string
   107  	if len(rawData) > 0 {
   108  		raw = rawData[len(rawData)-1]
   109  	}
   110  
   111  	// Required: false
   112  	// AllowEmptyValue: false
   113  	if raw == "" { // empty values pass all other validations
   114  		// Default values have been previously initialized by NewListTasksParams()
   115  		return nil
   116  	}
   117  
   118  	value, err := swag.ConvertInt32(raw)
   119  	if err != nil {
   120  		return errors.InvalidType("pageSize", "query", "int32", raw)
   121  	}
   122  	o.PageSize = &value
   123  
   124  	return nil
   125  }
   126  
   127  // bindSinceID binds and validates parameter SinceID from query.
   128  func (o *ListTasksParams) bindSinceID(rawData []string, hasKey bool, formats strfmt.Registry) error {
   129  	var raw string
   130  	if len(rawData) > 0 {
   131  		raw = rawData[len(rawData)-1]
   132  	}
   133  
   134  	// Required: false
   135  	// AllowEmptyValue: false
   136  	if raw == "" { // empty values pass all other validations
   137  		return nil
   138  	}
   139  
   140  	value, err := swag.ConvertInt64(raw)
   141  	if err != nil {
   142  		return errors.InvalidType("sinceId", "query", "int64", raw)
   143  	}
   144  	o.SinceID = &value
   145  
   146  	return nil
   147  }
   148  
   149  // bindStatus binds and validates array parameter Status from query.
   150  //
   151  // Arrays are parsed according to CollectionFormat: "pipes" (defaults to "csv" when empty).
   152  func (o *ListTasksParams) bindStatus(rawData []string, hasKey bool, formats strfmt.Registry) error {
   153  
   154  	var qvStatus string
   155  	if len(rawData) > 0 {
   156  		qvStatus = rawData[len(rawData)-1]
   157  	}
   158  
   159  	// CollectionFormat: pipes
   160  	statusIC := swag.SplitByFormat(qvStatus, "pipes")
   161  	if len(statusIC) == 0 {
   162  		return nil
   163  	}
   164  
   165  	var statusIR []string
   166  	for i, statusIV := range statusIC {
   167  		statusI := statusIV
   168  
   169  		if err := validate.Enum(fmt.Sprintf("%s.%v", "status", i), "query", statusI, []interface{}{"open", "closed", "ignored", "rejected"}); err != nil {
   170  			return err
   171  		}
   172  
   173  		statusIR = append(statusIR, statusI)
   174  	}
   175  
   176  	o.Status = statusIR
   177  	if err := o.validateStatus(formats); err != nil {
   178  		return err
   179  	}
   180  
   181  	return nil
   182  }
   183  
   184  // validateStatus carries on validations for parameter Status
   185  func (o *ListTasksParams) validateStatus(formats strfmt.Registry) error {
   186  
   187  	// uniqueItems: true
   188  	if err := validate.UniqueItems("status", "query", o.Status); err != nil {
   189  		return err
   190  	}
   191  
   192  	return nil
   193  }
   194  
   195  // bindTags binds and validates array parameter Tags from query.
   196  //
   197  // Arrays are parsed according to CollectionFormat: "" (defaults to "csv" when empty).
   198  func (o *ListTasksParams) bindTags(rawData []string, hasKey bool, formats strfmt.Registry) error {
   199  
   200  	var qvTags string
   201  	if len(rawData) > 0 {
   202  		qvTags = rawData[len(rawData)-1]
   203  	}
   204  
   205  	// CollectionFormat:
   206  	tagsIC := swag.SplitByFormat(qvTags, "")
   207  	if len(tagsIC) == 0 {
   208  		return nil
   209  	}
   210  
   211  	var tagsIR []string
   212  	for _, tagsIV := range tagsIC {
   213  		tagsI := tagsIV
   214  
   215  		tagsIR = append(tagsIR, tagsI)
   216  	}
   217  
   218  	o.Tags = tagsIR
   219  	if err := o.validateTags(formats); err != nil {
   220  		return err
   221  	}
   222  
   223  	return nil
   224  }
   225  
   226  // validateTags carries on validations for parameter Tags
   227  func (o *ListTasksParams) validateTags(formats strfmt.Registry) error {
   228  
   229  	// uniqueItems: true
   230  	if err := validate.UniqueItems("tags", "query", o.Tags); err != nil {
   231  		return err
   232  	}
   233  
   234  	return nil
   235  }