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