github.com/cilium/cilium@v1.16.2/api/v1/server/restapi/service/put_service_id_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 service 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 "io" 13 "net/http" 14 15 "github.com/go-openapi/errors" 16 "github.com/go-openapi/runtime" 17 "github.com/go-openapi/runtime/middleware" 18 "github.com/go-openapi/strfmt" 19 "github.com/go-openapi/swag" 20 "github.com/go-openapi/validate" 21 22 "github.com/cilium/cilium/api/v1/models" 23 ) 24 25 // NewPutServiceIDParams creates a new PutServiceIDParams object 26 // 27 // There are no default values defined in the spec. 28 func NewPutServiceIDParams() PutServiceIDParams { 29 30 return PutServiceIDParams{} 31 } 32 33 // PutServiceIDParams contains all the bound params for the put service ID operation 34 // typically these are obtained from a http.Request 35 // 36 // swagger:parameters PutServiceID 37 type PutServiceIDParams struct { 38 39 // HTTP Request Object 40 HTTPRequest *http.Request `json:"-"` 41 42 /*Service configuration 43 Required: true 44 In: body 45 */ 46 Config *models.ServiceSpec 47 /*ID of service 48 Required: true 49 In: path 50 */ 51 ID int64 52 } 53 54 // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface 55 // for simple values it will use straight method calls. 56 // 57 // To ensure default values, the struct must have been initialized with NewPutServiceIDParams() beforehand. 58 func (o *PutServiceIDParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { 59 var res []error 60 61 o.HTTPRequest = r 62 63 if runtime.HasBody(r) { 64 defer r.Body.Close() 65 var body models.ServiceSpec 66 if err := route.Consumer.Consume(r.Body, &body); err != nil { 67 if err == io.EOF { 68 res = append(res, errors.Required("config", "body", "")) 69 } else { 70 res = append(res, errors.NewParseError("config", "body", "", err)) 71 } 72 } else { 73 // validate body object 74 if err := body.Validate(route.Formats); err != nil { 75 res = append(res, err) 76 } 77 78 ctx := validate.WithOperationRequest(r.Context()) 79 if err := body.ContextValidate(ctx, route.Formats); err != nil { 80 res = append(res, err) 81 } 82 83 if len(res) == 0 { 84 o.Config = &body 85 } 86 } 87 } else { 88 res = append(res, errors.Required("config", "body", "")) 89 } 90 91 rID, rhkID, _ := route.Params.GetOK("id") 92 if err := o.bindID(rID, rhkID, route.Formats); err != nil { 93 res = append(res, err) 94 } 95 if len(res) > 0 { 96 return errors.CompositeValidationError(res...) 97 } 98 return nil 99 } 100 101 // bindID binds and validates parameter ID from path. 102 func (o *PutServiceIDParams) bindID(rawData []string, hasKey bool, formats strfmt.Registry) error { 103 var raw string 104 if len(rawData) > 0 { 105 raw = rawData[len(rawData)-1] 106 } 107 108 // Required: true 109 // Parameter is provided by construction from the route 110 111 value, err := swag.ConvertInt64(raw) 112 if err != nil { 113 return errors.InvalidType("id", "path", "int64", raw) 114 } 115 o.ID = value 116 117 return nil 118 }