github.com/kaisawind/go-swagger@v0.19.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/swag"
    16  
    17  	strfmt "github.com/go-openapi/strfmt"
    18  
    19  	models "github.com/go-swagger/go-swagger/examples/task-tracker/models"
    20  )
    21  
    22  // NewUpdateTaskParams creates a new UpdateTaskParams object
    23  // no default values defined in spec.
    24  func NewUpdateTaskParams() UpdateTaskParams {
    25  
    26  	return UpdateTaskParams{}
    27  }
    28  
    29  // UpdateTaskParams contains all the bound params for the update task operation
    30  // typically these are obtained from a http.Request
    31  //
    32  // swagger:parameters updateTask
    33  type UpdateTaskParams struct {
    34  
    35  	// HTTP Request Object
    36  	HTTPRequest *http.Request `json:"-"`
    37  
    38  	/*The task to update
    39  	  Required: true
    40  	  In: body
    41  	*/
    42  	Body *models.Task
    43  	/*The id of the item
    44  	  Required: true
    45  	  In: path
    46  	*/
    47  	ID int64
    48  }
    49  
    50  // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
    51  // for simple values it will use straight method calls.
    52  //
    53  // To ensure default values, the struct must have been initialized with NewUpdateTaskParams() beforehand.
    54  func (o *UpdateTaskParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    55  	var res []error
    56  
    57  	o.HTTPRequest = r
    58  
    59  	if runtime.HasBody(r) {
    60  		defer r.Body.Close()
    61  		var body models.Task
    62  		if err := route.Consumer.Consume(r.Body, &body); err != nil {
    63  			if err == io.EOF {
    64  				res = append(res, errors.Required("body", "body"))
    65  			} else {
    66  				res = append(res, errors.NewParseError("body", "body", "", err))
    67  			}
    68  		} else {
    69  			// validate body object
    70  			if err := body.Validate(route.Formats); err != nil {
    71  				res = append(res, err)
    72  			}
    73  
    74  			if len(res) == 0 {
    75  				o.Body = &body
    76  			}
    77  		}
    78  	} else {
    79  		res = append(res, errors.Required("body", "body"))
    80  	}
    81  	rID, rhkID, _ := route.Params.GetOK("id")
    82  	if err := o.bindID(rID, rhkID, 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 *UpdateTaskParams) 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  }