github.com/kata-containers/runtime@v0.0.0-20210505125100-04f29832a923/virtcontainers/pkg/firecracker/client/models/token_bucket.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 "github.com/go-openapi/validate" 14 ) 15 16 // TokenBucket Defines a token bucket with a maximum capacity (size), an initial burst size (one_time_burst) and an interval for refilling purposes (refill_time). The refill-rate is derived from size and refill_time, and it is the constant rate at which the tokens replenish. The refill process only starts happening after the initial burst budget is consumed. Consumption from the token bucket is unbounded in speed which allows for bursts bound in size by the amount of tokens available. Once the token bucket is empty, consumption speed is bound by the refill_rate. 17 // swagger:model TokenBucket 18 type TokenBucket struct { 19 20 // The initial size of a token bucket. 21 // Minimum: 0 22 OneTimeBurst *int64 `json:"one_time_burst,omitempty"` 23 24 // The amount of milliseconds it takes for the bucket to refill. 25 // Required: true 26 // Minimum: 0 27 RefillTime *int64 `json:"refill_time"` 28 29 // The total number of tokens this bucket can hold. 30 // Required: true 31 // Minimum: 0 32 Size *int64 `json:"size"` 33 } 34 35 // Validate validates this token bucket 36 func (m *TokenBucket) Validate(formats strfmt.Registry) error { 37 var res []error 38 39 if err := m.validateOneTimeBurst(formats); err != nil { 40 res = append(res, err) 41 } 42 43 if err := m.validateRefillTime(formats); err != nil { 44 res = append(res, err) 45 } 46 47 if err := m.validateSize(formats); err != nil { 48 res = append(res, err) 49 } 50 51 if len(res) > 0 { 52 return errors.CompositeValidationError(res...) 53 } 54 return nil 55 } 56 57 func (m *TokenBucket) validateOneTimeBurst(formats strfmt.Registry) error { 58 59 if swag.IsZero(m.OneTimeBurst) { // not required 60 return nil 61 } 62 63 if err := validate.MinimumInt("one_time_burst", "body", int64(*m.OneTimeBurst), 0, false); err != nil { 64 return err 65 } 66 67 return nil 68 } 69 70 func (m *TokenBucket) validateRefillTime(formats strfmt.Registry) error { 71 72 if err := validate.Required("refill_time", "body", m.RefillTime); err != nil { 73 return err 74 } 75 76 if err := validate.MinimumInt("refill_time", "body", int64(*m.RefillTime), 0, false); err != nil { 77 return err 78 } 79 80 return nil 81 } 82 83 func (m *TokenBucket) validateSize(formats strfmt.Registry) error { 84 85 if err := validate.Required("size", "body", m.Size); err != nil { 86 return err 87 } 88 89 if err := validate.MinimumInt("size", "body", int64(*m.Size), 0, false); err != nil { 90 return err 91 } 92 93 return nil 94 } 95 96 // MarshalBinary interface implementation 97 func (m *TokenBucket) MarshalBinary() ([]byte, error) { 98 if m == nil { 99 return nil, nil 100 } 101 return swag.WriteJSON(m) 102 } 103 104 // UnmarshalBinary interface implementation 105 func (m *TokenBucket) UnmarshalBinary(b []byte) error { 106 var res TokenBucket 107 if err := swag.ReadJSON(b, &res); err != nil { 108 return err 109 } 110 *m = res 111 return nil 112 }