github.com/josephspurrier/go-swagger@v0.2.1-0.20221129144919-1f672a142a00/examples/tutorials/custom-server/gen/restapi/operations/get_greeting_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"
    13  	"github.com/go-openapi/runtime/middleware"
    14  	"github.com/go-openapi/strfmt"
    15  )
    16  
    17  // NewGetGreetingParams creates a new GetGreetingParams object
    18  //
    19  // There are no default values defined in the spec.
    20  func NewGetGreetingParams() GetGreetingParams {
    21  
    22  	return GetGreetingParams{}
    23  }
    24  
    25  // GetGreetingParams contains all the bound params for the get greeting operation
    26  // typically these are obtained from a http.Request
    27  //
    28  // swagger:parameters getGreeting
    29  type GetGreetingParams struct {
    30  
    31  	// HTTP Request Object
    32  	HTTPRequest *http.Request `json:"-"`
    33  
    34  	/*defaults to World if not given
    35  	  In: query
    36  	*/
    37  	Name *string
    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 NewGetGreetingParams() beforehand.
    44  func (o *GetGreetingParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    45  	var res []error
    46  
    47  	o.HTTPRequest = r
    48  
    49  	qs := runtime.Values(r.URL.Query())
    50  
    51  	qName, qhkName, _ := qs.GetOK("name")
    52  	if err := o.bindName(qName, qhkName, route.Formats); err != nil {
    53  		res = append(res, err)
    54  	}
    55  	if len(res) > 0 {
    56  		return errors.CompositeValidationError(res...)
    57  	}
    58  	return nil
    59  }
    60  
    61  // bindName binds and validates parameter Name from query.
    62  func (o *GetGreetingParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error {
    63  	var raw string
    64  	if len(rawData) > 0 {
    65  		raw = rawData[len(rawData)-1]
    66  	}
    67  
    68  	// Required: false
    69  	// AllowEmptyValue: false
    70  
    71  	if raw == "" { // empty values pass all other validations
    72  		return nil
    73  	}
    74  	o.Name = &raw
    75  
    76  	return nil
    77  }