github.com/djarvur/go-swagger@v0.18.0/examples/generated/restapi/operations/user/create_users_with_array_input_parameters.go (about)

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