github.com/cilium/cilium@v1.16.2/api/v1/server/restapi/policy/get_ip_parameters.go (about)

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  // Copyright Authors of Cilium
     4  // SPDX-License-Identifier: Apache-2.0
     5  
     6  package policy
     7  
     8  // This file was generated by the swagger tool.
     9  // Editing this file might prove futile when you re-run the swagger generate command
    10  
    11  import (
    12  	"net/http"
    13  
    14  	"github.com/go-openapi/errors"
    15  	"github.com/go-openapi/runtime"
    16  	"github.com/go-openapi/runtime/middleware"
    17  	"github.com/go-openapi/strfmt"
    18  )
    19  
    20  // NewGetIPParams creates a new GetIPParams object
    21  //
    22  // There are no default values defined in the spec.
    23  func NewGetIPParams() GetIPParams {
    24  
    25  	return GetIPParams{}
    26  }
    27  
    28  // GetIPParams contains all the bound params for the get IP operation
    29  // typically these are obtained from a http.Request
    30  //
    31  // swagger:parameters GetIP
    32  type GetIPParams struct {
    33  
    34  	// HTTP Request Object
    35  	HTTPRequest *http.Request `json:"-"`
    36  
    37  	/*A CIDR range of IPs
    38  	  In: query
    39  	*/
    40  	Cidr *string
    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 NewGetIPParams() beforehand.
    47  func (o *GetIPParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
    48  	var res []error
    49  
    50  	o.HTTPRequest = r
    51  
    52  	qs := runtime.Values(r.URL.Query())
    53  
    54  	qCidr, qhkCidr, _ := qs.GetOK("cidr")
    55  	if err := o.bindCidr(qCidr, qhkCidr, route.Formats); err != nil {
    56  		res = append(res, err)
    57  	}
    58  	if len(res) > 0 {
    59  		return errors.CompositeValidationError(res...)
    60  	}
    61  	return nil
    62  }
    63  
    64  // bindCidr binds and validates parameter Cidr from query.
    65  func (o *GetIPParams) bindCidr(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: false
    72  	// AllowEmptyValue: false
    73  
    74  	if raw == "" { // empty values pass all other validations
    75  		return nil
    76  	}
    77  	o.Cidr = &raw
    78  
    79  	return nil
    80  }