github.com/kaisawind/go-swagger@v0.19.0/examples/stream-server/restapi/operations/elapse_parameters.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  package operations
     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/middleware"
    13  	"github.com/go-openapi/swag"
    14  	"github.com/go-openapi/validate"
    15  
    16  	strfmt "github.com/go-openapi/strfmt"
    17  )
    18  
    19  // NewElapseParams creates a new ElapseParams object
    20  // no default values defined in spec.
    21  func NewElapseParams() ElapseParams {
    22  
    23  	return ElapseParams{}
    24  }
    25  
    26  // ElapseParams contains all the bound params for the elapse operation
    27  // typically these are obtained from a http.Request
    28  //
    29  // swagger:parameters elapse
    30  type ElapseParams struct {
    31  
    32  	// HTTP Request Object
    33  	HTTPRequest *http.Request `json:"-"`
    34  
    35  	/*How many seconds to count down
    36  	  Required: true
    37  	  Maximum: 30
    38  	  Minimum: 2
    39  	  In: path
    40  	*/
    41  	Length int64
    42  }
    43  
    44  // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
    45  // for simple values it will use straight method calls.
    46  //
    47  // To ensure default values, the struct must have been initialized with NewElapseParams() beforehand.
    48  func (o *ElapseParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    49  	var res []error
    50  
    51  	o.HTTPRequest = r
    52  
    53  	rLength, rhkLength, _ := route.Params.GetOK("length")
    54  	if err := o.bindLength(rLength, rhkLength, route.Formats); err != nil {
    55  		res = append(res, err)
    56  	}
    57  
    58  	if len(res) > 0 {
    59  		return errors.CompositeValidationError(res...)
    60  	}
    61  	return nil
    62  }
    63  
    64  // bindLength binds and validates parameter Length from path.
    65  func (o *ElapseParams) bindLength(rawData []string, hasKey bool, formats strfmt.Registry) error {
    66  	var raw string
    67  	if len(rawData) > 0 {
    68  		raw = rawData[len(rawData)-1]
    69  	}
    70  
    71  	// Required: true
    72  	// Parameter is provided by construction from the route
    73  
    74  	value, err := swag.ConvertInt64(raw)
    75  	if err != nil {
    76  		return errors.InvalidType("length", "path", "int64", raw)
    77  	}
    78  	o.Length = value
    79  
    80  	if err := o.validateLength(formats); err != nil {
    81  		return err
    82  	}
    83  
    84  	return nil
    85  }
    86  
    87  // validateLength carries on validations for parameter Length
    88  func (o *ElapseParams) validateLength(formats strfmt.Registry) error {
    89  
    90  	if err := validate.MinimumInt("length", "path", int64(o.Length), 2, false); err != nil {
    91  		return err
    92  	}
    93  
    94  	if err := validate.MaximumInt("length", "path", int64(o.Length), 30, false); err != nil {
    95  		return err
    96  	}
    97  
    98  	return nil
    99  }