github.com/go-swagger/go-swagger@v0.31.0/examples/task-tracker/restapi/operations/tasks/update_task_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  	"io"
    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/strfmt"
    16  	"github.com/go-openapi/swag"
    17  	"github.com/go-openapi/validate"
    18  
    19  	"github.com/go-swagger/go-swagger/examples/task-tracker/models"
    20  )
    21  
    22  // NewUpdateTaskParams creates a new UpdateTaskParams object
    23  //
    24  // There are no default values defined in the spec.
    25  func NewUpdateTaskParams() UpdateTaskParams {
    26  
    27  	return UpdateTaskParams{}
    28  }
    29  
    30  // UpdateTaskParams contains all the bound params for the update task operation
    31  // typically these are obtained from a http.Request
    32  //
    33  // swagger:parameters updateTask
    34  type UpdateTaskParams struct {
    35  
    36  	// HTTP Request Object
    37  	HTTPRequest *http.Request `json:"-"`
    38  
    39  	/*The task to update
    40  	  Required: true
    41  	  In: body
    42  	*/
    43  	Body *models.Task
    44  	/*The id of the item
    45  	  Required: true
    46  	  In: path
    47  	*/
    48  	ID int64
    49  }
    50  
    51  // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
    52  // for simple values it will use straight method calls.
    53  //
    54  // To ensure default values, the struct must have been initialized with NewUpdateTaskParams() beforehand.
    55  func (o *UpdateTaskParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    56  	var res []error
    57  
    58  	o.HTTPRequest = r
    59  
    60  	if runtime.HasBody(r) {
    61  		defer r.Body.Close()
    62  		var body models.Task
    63  		if err := route.Consumer.Consume(r.Body, &body); err != nil {
    64  			if err == io.EOF {
    65  				res = append(res, errors.Required("body", "body", ""))
    66  			} else {
    67  				res = append(res, errors.NewParseError("body", "body", "", err))
    68  			}
    69  		} else {
    70  			// validate body object
    71  			if err := body.Validate(route.Formats); err != nil {
    72  				res = append(res, err)
    73  			}
    74  
    75  			ctx := validate.WithOperationRequest(r.Context())
    76  			if err := body.ContextValidate(ctx, route.Formats); err != nil {
    77  				res = append(res, err)
    78  			}
    79  
    80  			if len(res) == 0 {
    81  				o.Body = &body
    82  			}
    83  		}
    84  	} else {
    85  		res = append(res, errors.Required("body", "body", ""))
    86  	}
    87  
    88  	rID, rhkID, _ := route.Params.GetOK("id")
    89  	if err := o.bindID(rID, rhkID, route.Formats); err != nil {
    90  		res = append(res, err)
    91  	}
    92  	if len(res) > 0 {
    93  		return errors.CompositeValidationError(res...)
    94  	}
    95  	return nil
    96  }
    97  
    98  // bindID binds and validates parameter ID from path.
    99  func (o *UpdateTaskParams) bindID(rawData []string, hasKey bool, formats strfmt.Registry) error {
   100  	var raw string
   101  	if len(rawData) > 0 {
   102  		raw = rawData[len(rawData)-1]
   103  	}
   104  
   105  	// Required: true
   106  	// Parameter is provided by construction from the route
   107  
   108  	value, err := swag.ConvertInt64(raw)
   109  	if err != nil {
   110  		return errors.InvalidType("id", "path", "int64", raw)
   111  	}
   112  	o.ID = value
   113  
   114  	return nil
   115  }