github.com/crowdsecurity/crowdsec@v1.6.1/pkg/models/meta.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  )
    16  
    17  // Meta Meta
    18  //
    19  // the Meta data of the Alert itself
    20  //
    21  // swagger:model Meta
    22  type Meta []*MetaItems0
    23  
    24  // Validate validates this meta
    25  func (m Meta) Validate(formats strfmt.Registry) error {
    26  	var res []error
    27  
    28  	for i := 0; i < len(m); i++ {
    29  		if swag.IsZero(m[i]) { // not required
    30  			continue
    31  		}
    32  
    33  		if m[i] != nil {
    34  			if err := m[i].Validate(formats); err != nil {
    35  				if ve, ok := err.(*errors.Validation); ok {
    36  					return ve.ValidateName(strconv.Itoa(i))
    37  				} else if ce, ok := err.(*errors.CompositeError); ok {
    38  					return ce.ValidateName(strconv.Itoa(i))
    39  				}
    40  				return err
    41  			}
    42  		}
    43  
    44  	}
    45  
    46  	if len(res) > 0 {
    47  		return errors.CompositeValidationError(res...)
    48  	}
    49  	return nil
    50  }
    51  
    52  // ContextValidate validate this meta based on the context it is used
    53  func (m Meta) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    54  	var res []error
    55  
    56  	for i := 0; i < len(m); i++ {
    57  
    58  		if m[i] != nil {
    59  
    60  			if swag.IsZero(m[i]) { // not required
    61  				return nil
    62  			}
    63  
    64  			if err := m[i].ContextValidate(ctx, formats); err != nil {
    65  				if ve, ok := err.(*errors.Validation); ok {
    66  					return ve.ValidateName(strconv.Itoa(i))
    67  				} else if ce, ok := err.(*errors.CompositeError); ok {
    68  					return ce.ValidateName(strconv.Itoa(i))
    69  				}
    70  				return err
    71  			}
    72  		}
    73  
    74  	}
    75  
    76  	if len(res) > 0 {
    77  		return errors.CompositeValidationError(res...)
    78  	}
    79  	return nil
    80  }
    81  
    82  // MetaItems0 meta items0
    83  //
    84  // swagger:model MetaItems0
    85  type MetaItems0 struct {
    86  
    87  	// key
    88  	Key string `json:"key,omitempty"`
    89  
    90  	// value
    91  	Value string `json:"value,omitempty"`
    92  }
    93  
    94  // Validate validates this meta items0
    95  func (m *MetaItems0) Validate(formats strfmt.Registry) error {
    96  	return nil
    97  }
    98  
    99  // ContextValidate validates this meta items0 based on context it is used
   100  func (m *MetaItems0) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   101  	return nil
   102  }
   103  
   104  // MarshalBinary interface implementation
   105  func (m *MetaItems0) MarshalBinary() ([]byte, error) {
   106  	if m == nil {
   107  		return nil, nil
   108  	}
   109  	return swag.WriteJSON(m)
   110  }
   111  
   112  // UnmarshalBinary interface implementation
   113  func (m *MetaItems0) UnmarshalBinary(b []byte) error {
   114  	var res MetaItems0
   115  	if err := swag.ReadJSON(b, &res); err != nil {
   116  		return err
   117  	}
   118  	*m = res
   119  	return nil
   120  }