github.com/cilium/cilium@v1.16.2/api/v1/models/map_event.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  	"encoding/json"
    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  // MapEvent Event on Map
    22  //
    23  // swagger:model MapEvent
    24  type MapEvent struct {
    25  
    26  	// Action type for event
    27  	// Enum: [update delete]
    28  	Action string `json:"action,omitempty"`
    29  
    30  	// Desired action to be performed after this event
    31  	// Enum: [ok insert delete]
    32  	DesiredAction string `json:"desired-action,omitempty"`
    33  
    34  	// Map key on which the event occured
    35  	Key string `json:"key,omitempty"`
    36  
    37  	// Last error seen while performing desired action
    38  	LastError string `json:"last-error,omitempty"`
    39  
    40  	// Timestamp when the event occurred
    41  	// Format: date-time
    42  	Timestamp strfmt.DateTime `json:"timestamp,omitempty"`
    43  
    44  	// Map value on which the event occured
    45  	Value string `json:"value,omitempty"`
    46  }
    47  
    48  // Validate validates this map event
    49  func (m *MapEvent) Validate(formats strfmt.Registry) error {
    50  	var res []error
    51  
    52  	if err := m.validateAction(formats); err != nil {
    53  		res = append(res, err)
    54  	}
    55  
    56  	if err := m.validateDesiredAction(formats); err != nil {
    57  		res = append(res, err)
    58  	}
    59  
    60  	if err := m.validateTimestamp(formats); err != nil {
    61  		res = append(res, err)
    62  	}
    63  
    64  	if len(res) > 0 {
    65  		return errors.CompositeValidationError(res...)
    66  	}
    67  	return nil
    68  }
    69  
    70  var mapEventTypeActionPropEnum []interface{}
    71  
    72  func init() {
    73  	var res []string
    74  	if err := json.Unmarshal([]byte(`["update","delete"]`), &res); err != nil {
    75  		panic(err)
    76  	}
    77  	for _, v := range res {
    78  		mapEventTypeActionPropEnum = append(mapEventTypeActionPropEnum, v)
    79  	}
    80  }
    81  
    82  const (
    83  
    84  	// MapEventActionUpdate captures enum value "update"
    85  	MapEventActionUpdate string = "update"
    86  
    87  	// MapEventActionDelete captures enum value "delete"
    88  	MapEventActionDelete string = "delete"
    89  )
    90  
    91  // prop value enum
    92  func (m *MapEvent) validateActionEnum(path, location string, value string) error {
    93  	if err := validate.EnumCase(path, location, value, mapEventTypeActionPropEnum, true); err != nil {
    94  		return err
    95  	}
    96  	return nil
    97  }
    98  
    99  func (m *MapEvent) validateAction(formats strfmt.Registry) error {
   100  	if swag.IsZero(m.Action) { // not required
   101  		return nil
   102  	}
   103  
   104  	// value enum
   105  	if err := m.validateActionEnum("action", "body", m.Action); err != nil {
   106  		return err
   107  	}
   108  
   109  	return nil
   110  }
   111  
   112  var mapEventTypeDesiredActionPropEnum []interface{}
   113  
   114  func init() {
   115  	var res []string
   116  	if err := json.Unmarshal([]byte(`["ok","insert","delete"]`), &res); err != nil {
   117  		panic(err)
   118  	}
   119  	for _, v := range res {
   120  		mapEventTypeDesiredActionPropEnum = append(mapEventTypeDesiredActionPropEnum, v)
   121  	}
   122  }
   123  
   124  const (
   125  
   126  	// MapEventDesiredActionOk captures enum value "ok"
   127  	MapEventDesiredActionOk string = "ok"
   128  
   129  	// MapEventDesiredActionInsert captures enum value "insert"
   130  	MapEventDesiredActionInsert string = "insert"
   131  
   132  	// MapEventDesiredActionDelete captures enum value "delete"
   133  	MapEventDesiredActionDelete string = "delete"
   134  )
   135  
   136  // prop value enum
   137  func (m *MapEvent) validateDesiredActionEnum(path, location string, value string) error {
   138  	if err := validate.EnumCase(path, location, value, mapEventTypeDesiredActionPropEnum, true); err != nil {
   139  		return err
   140  	}
   141  	return nil
   142  }
   143  
   144  func (m *MapEvent) validateDesiredAction(formats strfmt.Registry) error {
   145  	if swag.IsZero(m.DesiredAction) { // not required
   146  		return nil
   147  	}
   148  
   149  	// value enum
   150  	if err := m.validateDesiredActionEnum("desired-action", "body", m.DesiredAction); err != nil {
   151  		return err
   152  	}
   153  
   154  	return nil
   155  }
   156  
   157  func (m *MapEvent) validateTimestamp(formats strfmt.Registry) error {
   158  	if swag.IsZero(m.Timestamp) { // not required
   159  		return nil
   160  	}
   161  
   162  	if err := validate.FormatOf("timestamp", "body", "date-time", m.Timestamp.String(), formats); err != nil {
   163  		return err
   164  	}
   165  
   166  	return nil
   167  }
   168  
   169  // ContextValidate validates this map event based on context it is used
   170  func (m *MapEvent) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   171  	return nil
   172  }
   173  
   174  // MarshalBinary interface implementation
   175  func (m *MapEvent) MarshalBinary() ([]byte, error) {
   176  	if m == nil {
   177  		return nil, nil
   178  	}
   179  	return swag.WriteJSON(m)
   180  }
   181  
   182  // UnmarshalBinary interface implementation
   183  func (m *MapEvent) UnmarshalBinary(b []byte) error {
   184  	var res MapEvent
   185  	if err := swag.ReadJSON(b, &res); err != nil {
   186  		return err
   187  	}
   188  	*m = res
   189  	return nil
   190  }