github.com/circl-dev/go-swagger@v0.31.0/examples/todo-list/restapi/operations/todos/add_one_parameters.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package todos
     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/circl-dev/runtime"
    14  	"github.com/circl-dev/runtime/middleware"
    15  	"github.com/circl-dev/validate"
    16  
    17  	"github.com/circl-dev/go-swagger/examples/todo-list/models"
    18  )
    19  
    20  // NewAddOneParams creates a new AddOneParams object
    21  //
    22  // There are no default values defined in the spec.
    23  func NewAddOneParams() AddOneParams {
    24  
    25  	return AddOneParams{}
    26  }
    27  
    28  // AddOneParams contains all the bound params for the add one operation
    29  // typically these are obtained from a http.Request
    30  //
    31  // swagger:parameters addOne
    32  type AddOneParams struct {
    33  
    34  	// HTTP Request Object
    35  	HTTPRequest *http.Request `json:"-"`
    36  
    37  	/*
    38  	  In: body
    39  	*/
    40  	Body *models.Item
    41  }
    42  
    43  // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
    44  // for simple values it will use straight method calls.
    45  //
    46  // To ensure default values, the struct must have been initialized with NewAddOneParams() beforehand.
    47  func (o *AddOneParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    48  	var res []error
    49  
    50  	o.HTTPRequest = r
    51  
    52  	if runtime.HasBody(r) {
    53  		defer r.Body.Close()
    54  		var body models.Item
    55  		if err := route.Consumer.Consume(r.Body, &body); err != nil {
    56  			res = append(res, errors.NewParseError("body", "body", "", err))
    57  		} else {
    58  			// validate body object
    59  			if err := body.Validate(route.Formats); err != nil {
    60  				res = append(res, err)
    61  			}
    62  
    63  			ctx := validate.WithOperationRequest(context.Background())
    64  			if err := body.ContextValidate(ctx, route.Formats); err != nil {
    65  				res = append(res, err)
    66  			}
    67  
    68  			if len(res) == 0 {
    69  				o.Body = &body
    70  			}
    71  		}
    72  	}
    73  	if len(res) > 0 {
    74  		return errors.CompositeValidationError(res...)
    75  	}
    76  	return nil
    77  }