github.com/kata-containers/runtime@v0.0.0-20210505125100-04f29832a923/virtcontainers/pkg/firecracker/client/models/rate_limiter.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package models 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 strfmt "github.com/go-openapi/strfmt" 10 11 "github.com/go-openapi/errors" 12 "github.com/go-openapi/swag" 13 ) 14 15 // RateLimiter Defines an IO rate limiter with independent bytes/s and ops/s limits. Limits are defined by configuring each of the _bandwidth_ and _ops_ token buckets. 16 // swagger:model RateLimiter 17 type RateLimiter struct { 18 19 // Token bucket with bytes as tokens 20 Bandwidth *TokenBucket `json:"bandwidth,omitempty"` 21 22 // Token bucket with operations as tokens 23 Ops *TokenBucket `json:"ops,omitempty"` 24 } 25 26 // Validate validates this rate limiter 27 func (m *RateLimiter) Validate(formats strfmt.Registry) error { 28 var res []error 29 30 if err := m.validateBandwidth(formats); err != nil { 31 res = append(res, err) 32 } 33 34 if err := m.validateOps(formats); err != nil { 35 res = append(res, err) 36 } 37 38 if len(res) > 0 { 39 return errors.CompositeValidationError(res...) 40 } 41 return nil 42 } 43 44 func (m *RateLimiter) validateBandwidth(formats strfmt.Registry) error { 45 46 if swag.IsZero(m.Bandwidth) { // not required 47 return nil 48 } 49 50 if m.Bandwidth != nil { 51 if err := m.Bandwidth.Validate(formats); err != nil { 52 if ve, ok := err.(*errors.Validation); ok { 53 return ve.ValidateName("bandwidth") 54 } 55 return err 56 } 57 } 58 59 return nil 60 } 61 62 func (m *RateLimiter) validateOps(formats strfmt.Registry) error { 63 64 if swag.IsZero(m.Ops) { // not required 65 return nil 66 } 67 68 if m.Ops != nil { 69 if err := m.Ops.Validate(formats); err != nil { 70 if ve, ok := err.(*errors.Validation); ok { 71 return ve.ValidateName("ops") 72 } 73 return err 74 } 75 } 76 77 return nil 78 } 79 80 // MarshalBinary interface implementation 81 func (m *RateLimiter) MarshalBinary() ([]byte, error) { 82 if m == nil { 83 return nil, nil 84 } 85 return swag.WriteJSON(m) 86 } 87 88 // UnmarshalBinary interface implementation 89 func (m *RateLimiter) UnmarshalBinary(b []byte) error { 90 var res RateLimiter 91 if err := swag.ReadJSON(b, &res); err != nil { 92 return err 93 } 94 *m = res 95 return nil 96 }