github.com/cilium/cilium@v1.16.2/api/v1/models/recorder_spec.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 models 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 "context" 13 "strconv" 14 15 "github.com/go-openapi/errors" 16 "github.com/go-openapi/strfmt" 17 "github.com/go-openapi/swag" 18 "github.com/go-openapi/validate" 19 ) 20 21 // RecorderSpec Configuration of a recorder 22 // 23 // swagger:model RecorderSpec 24 type RecorderSpec struct { 25 26 // Maximum packet length or zero for full packet length 27 CaptureLength int64 `json:"capture-length,omitempty"` 28 29 // List of wildcard filters for given recorder 30 // Required: true 31 Filters []*RecorderFilter `json:"filters"` 32 33 // Unique identification 34 // Required: true 35 ID *int64 `json:"id"` 36 } 37 38 // Validate validates this recorder spec 39 func (m *RecorderSpec) Validate(formats strfmt.Registry) error { 40 var res []error 41 42 if err := m.validateFilters(formats); err != nil { 43 res = append(res, err) 44 } 45 46 if err := m.validateID(formats); err != nil { 47 res = append(res, err) 48 } 49 50 if len(res) > 0 { 51 return errors.CompositeValidationError(res...) 52 } 53 return nil 54 } 55 56 func (m *RecorderSpec) validateFilters(formats strfmt.Registry) error { 57 58 if err := validate.Required("filters", "body", m.Filters); err != nil { 59 return err 60 } 61 62 for i := 0; i < len(m.Filters); i++ { 63 if swag.IsZero(m.Filters[i]) { // not required 64 continue 65 } 66 67 if m.Filters[i] != nil { 68 if err := m.Filters[i].Validate(formats); err != nil { 69 if ve, ok := err.(*errors.Validation); ok { 70 return ve.ValidateName("filters" + "." + strconv.Itoa(i)) 71 } else if ce, ok := err.(*errors.CompositeError); ok { 72 return ce.ValidateName("filters" + "." + strconv.Itoa(i)) 73 } 74 return err 75 } 76 } 77 78 } 79 80 return nil 81 } 82 83 func (m *RecorderSpec) validateID(formats strfmt.Registry) error { 84 85 if err := validate.Required("id", "body", m.ID); err != nil { 86 return err 87 } 88 89 return nil 90 } 91 92 // ContextValidate validate this recorder spec based on the context it is used 93 func (m *RecorderSpec) ContextValidate(ctx context.Context, formats strfmt.Registry) error { 94 var res []error 95 96 if err := m.contextValidateFilters(ctx, formats); err != nil { 97 res = append(res, err) 98 } 99 100 if len(res) > 0 { 101 return errors.CompositeValidationError(res...) 102 } 103 return nil 104 } 105 106 func (m *RecorderSpec) contextValidateFilters(ctx context.Context, formats strfmt.Registry) error { 107 108 for i := 0; i < len(m.Filters); i++ { 109 110 if m.Filters[i] != nil { 111 112 if swag.IsZero(m.Filters[i]) { // not required 113 return nil 114 } 115 116 if err := m.Filters[i].ContextValidate(ctx, formats); err != nil { 117 if ve, ok := err.(*errors.Validation); ok { 118 return ve.ValidateName("filters" + "." + strconv.Itoa(i)) 119 } else if ce, ok := err.(*errors.CompositeError); ok { 120 return ce.ValidateName("filters" + "." + strconv.Itoa(i)) 121 } 122 return err 123 } 124 } 125 126 } 127 128 return nil 129 } 130 131 // MarshalBinary interface implementation 132 func (m *RecorderSpec) MarshalBinary() ([]byte, error) { 133 if m == nil { 134 return nil, nil 135 } 136 return swag.WriteJSON(m) 137 } 138 139 // UnmarshalBinary interface implementation 140 func (m *RecorderSpec) UnmarshalBinary(b []byte) error { 141 var res RecorderSpec 142 if err := swag.ReadJSON(b, &res); err != nil { 143 return err 144 } 145 *m = res 146 return nil 147 }