github.com/crowdsecurity/crowdsec@v1.6.1/pkg/models/metrics.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 "context" 10 "strconv" 11 12 "github.com/go-openapi/errors" 13 "github.com/go-openapi/strfmt" 14 "github.com/go-openapi/swag" 15 "github.com/go-openapi/validate" 16 ) 17 18 // Metrics Metrics 19 // 20 // swagger:model Metrics 21 type Metrics struct { 22 23 // the local version of crowdsec/apil 24 // Required: true 25 ApilVersion *string `json:"apil_version"` 26 27 // bouncers 28 // Required: true 29 Bouncers []*MetricsBouncerInfo `json:"bouncers"` 30 31 // machines 32 // Required: true 33 Machines []*MetricsAgentInfo `json:"machines"` 34 } 35 36 // Validate validates this metrics 37 func (m *Metrics) Validate(formats strfmt.Registry) error { 38 var res []error 39 40 if err := m.validateApilVersion(formats); err != nil { 41 res = append(res, err) 42 } 43 44 if err := m.validateBouncers(formats); err != nil { 45 res = append(res, err) 46 } 47 48 if err := m.validateMachines(formats); err != nil { 49 res = append(res, err) 50 } 51 52 if len(res) > 0 { 53 return errors.CompositeValidationError(res...) 54 } 55 return nil 56 } 57 58 func (m *Metrics) validateApilVersion(formats strfmt.Registry) error { 59 60 if err := validate.Required("apil_version", "body", m.ApilVersion); err != nil { 61 return err 62 } 63 64 return nil 65 } 66 67 func (m *Metrics) validateBouncers(formats strfmt.Registry) error { 68 69 if err := validate.Required("bouncers", "body", m.Bouncers); err != nil { 70 return err 71 } 72 73 for i := 0; i < len(m.Bouncers); i++ { 74 if swag.IsZero(m.Bouncers[i]) { // not required 75 continue 76 } 77 78 if m.Bouncers[i] != nil { 79 if err := m.Bouncers[i].Validate(formats); err != nil { 80 if ve, ok := err.(*errors.Validation); ok { 81 return ve.ValidateName("bouncers" + "." + strconv.Itoa(i)) 82 } else if ce, ok := err.(*errors.CompositeError); ok { 83 return ce.ValidateName("bouncers" + "." + strconv.Itoa(i)) 84 } 85 return err 86 } 87 } 88 89 } 90 91 return nil 92 } 93 94 func (m *Metrics) validateMachines(formats strfmt.Registry) error { 95 96 if err := validate.Required("machines", "body", m.Machines); err != nil { 97 return err 98 } 99 100 for i := 0; i < len(m.Machines); i++ { 101 if swag.IsZero(m.Machines[i]) { // not required 102 continue 103 } 104 105 if m.Machines[i] != nil { 106 if err := m.Machines[i].Validate(formats); err != nil { 107 if ve, ok := err.(*errors.Validation); ok { 108 return ve.ValidateName("machines" + "." + strconv.Itoa(i)) 109 } else if ce, ok := err.(*errors.CompositeError); ok { 110 return ce.ValidateName("machines" + "." + strconv.Itoa(i)) 111 } 112 return err 113 } 114 } 115 116 } 117 118 return nil 119 } 120 121 // ContextValidate validate this metrics based on the context it is used 122 func (m *Metrics) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 123 var res []error 124 125 if err := m.contextValidateBouncers(ctx, formats); err != nil { 126 res = append(res, err) 127 } 128 129 if err := m.contextValidateMachines(ctx, formats); err != nil { 130 res = append(res, err) 131 } 132 133 if len(res) > 0 { 134 return errors.CompositeValidationError(res...) 135 } 136 return nil 137 } 138 139 func (m *Metrics) contextValidateBouncers(ctx context.Context, formats strfmt.Registry) error { 140 141 for i := 0; i < len(m.Bouncers); i++ { 142 143 if m.Bouncers[i] != nil { 144 145 if swag.IsZero(m.Bouncers[i]) { // not required 146 return nil 147 } 148 149 if err := m.Bouncers[i].ContextValidate(ctx, formats); err != nil { 150 if ve, ok := err.(*errors.Validation); ok { 151 return ve.ValidateName("bouncers" + "." + strconv.Itoa(i)) 152 } else if ce, ok := err.(*errors.CompositeError); ok { 153 return ce.ValidateName("bouncers" + "." + strconv.Itoa(i)) 154 } 155 return err 156 } 157 } 158 159 } 160 161 return nil 162 } 163 164 func (m *Metrics) contextValidateMachines(ctx context.Context, formats strfmt.Registry) error { 165 166 for i := 0; i < len(m.Machines); i++ { 167 168 if m.Machines[i] != nil { 169 170 if swag.IsZero(m.Machines[i]) { // not required 171 return nil 172 } 173 174 if err := m.Machines[i].ContextValidate(ctx, formats); err != nil { 175 if ve, ok := err.(*errors.Validation); ok { 176 return ve.ValidateName("machines" + "." + strconv.Itoa(i)) 177 } else if ce, ok := err.(*errors.CompositeError); ok { 178 return ce.ValidateName("machines" + "." + strconv.Itoa(i)) 179 } 180 return err 181 } 182 } 183 184 } 185 186 return nil 187 } 188 189 // MarshalBinary interface implementation 190 func (m *Metrics) MarshalBinary() ([]byte, error) { 191 if m == nil { 192 return nil, nil 193 } 194 return swag.WriteJSON(m) 195 } 196 197 // UnmarshalBinary interface implementation 198 func (m *Metrics) UnmarshalBinary(b []byte) error { 199 var res Metrics 200 if err := swag.ReadJSON(b, &res); err != nil { 201 return err 202 } 203 *m = res 204 return nil 205 }