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