github.com/cilium/cilium@v1.16.2/api/v1/models/trace_to.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  )
    19  
    20  // TraceTo trace to
    21  //
    22  // swagger:model TraceTo
    23  type TraceTo struct {
    24  
    25  	// List of Layer 4 port and protocol pairs which will be used in communication
    26  	// from the source identity to the destination identity.
    27  	//
    28  	Dports []*Port `json:"dports"`
    29  
    30  	// labels
    31  	Labels Labels `json:"labels,omitempty"`
    32  }
    33  
    34  // Validate validates this trace to
    35  func (m *TraceTo) Validate(formats strfmt.Registry) error {
    36  	var res []error
    37  
    38  	if err := m.validateDports(formats); err != nil {
    39  		res = append(res, err)
    40  	}
    41  
    42  	if err := m.validateLabels(formats); err != nil {
    43  		res = append(res, err)
    44  	}
    45  
    46  	if len(res) > 0 {
    47  		return errors.CompositeValidationError(res...)
    48  	}
    49  	return nil
    50  }
    51  
    52  func (m *TraceTo) validateDports(formats strfmt.Registry) error {
    53  	if swag.IsZero(m.Dports) { // not required
    54  		return nil
    55  	}
    56  
    57  	for i := 0; i < len(m.Dports); i++ {
    58  		if swag.IsZero(m.Dports[i]) { // not required
    59  			continue
    60  		}
    61  
    62  		if m.Dports[i] != nil {
    63  			if err := m.Dports[i].Validate(formats); err != nil {
    64  				if ve, ok := err.(*errors.Validation); ok {
    65  					return ve.ValidateName("dports" + "." + strconv.Itoa(i))
    66  				} else if ce, ok := err.(*errors.CompositeError); ok {
    67  					return ce.ValidateName("dports" + "." + strconv.Itoa(i))
    68  				}
    69  				return err
    70  			}
    71  		}
    72  
    73  	}
    74  
    75  	return nil
    76  }
    77  
    78  func (m *TraceTo) validateLabels(formats strfmt.Registry) error {
    79  	if swag.IsZero(m.Labels) { // not required
    80  		return nil
    81  	}
    82  
    83  	if err := m.Labels.Validate(formats); err != nil {
    84  		if ve, ok := err.(*errors.Validation); ok {
    85  			return ve.ValidateName("labels")
    86  		} else if ce, ok := err.(*errors.CompositeError); ok {
    87  			return ce.ValidateName("labels")
    88  		}
    89  		return err
    90  	}
    91  
    92  	return nil
    93  }
    94  
    95  // ContextValidate validate this trace to based on the context it is used
    96  func (m *TraceTo) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    97  	var res []error
    98  
    99  	if err := m.contextValidateDports(ctx, formats); err != nil {
   100  		res = append(res, err)
   101  	}
   102  
   103  	if err := m.contextValidateLabels(ctx, formats); err != nil {
   104  		res = append(res, err)
   105  	}
   106  
   107  	if len(res) > 0 {
   108  		return errors.CompositeValidationError(res...)
   109  	}
   110  	return nil
   111  }
   112  
   113  func (m *TraceTo) contextValidateDports(ctx context.Context, formats strfmt.Registry) error {
   114  
   115  	for i := 0; i < len(m.Dports); i++ {
   116  
   117  		if m.Dports[i] != nil {
   118  
   119  			if swag.IsZero(m.Dports[i]) { // not required
   120  				return nil
   121  			}
   122  
   123  			if err := m.Dports[i].ContextValidate(ctx, formats); err != nil {
   124  				if ve, ok := err.(*errors.Validation); ok {
   125  					return ve.ValidateName("dports" + "." + strconv.Itoa(i))
   126  				} else if ce, ok := err.(*errors.CompositeError); ok {
   127  					return ce.ValidateName("dports" + "." + strconv.Itoa(i))
   128  				}
   129  				return err
   130  			}
   131  		}
   132  
   133  	}
   134  
   135  	return nil
   136  }
   137  
   138  func (m *TraceTo) contextValidateLabels(ctx context.Context, formats strfmt.Registry) error {
   139  
   140  	if err := m.Labels.ContextValidate(ctx, formats); err != nil {
   141  		if ve, ok := err.(*errors.Validation); ok {
   142  			return ve.ValidateName("labels")
   143  		} else if ce, ok := err.(*errors.CompositeError); ok {
   144  			return ce.ValidateName("labels")
   145  		}
   146  		return err
   147  	}
   148  
   149  	return nil
   150  }
   151  
   152  // MarshalBinary interface implementation
   153  func (m *TraceTo) MarshalBinary() ([]byte, error) {
   154  	if m == nil {
   155  		return nil, nil
   156  	}
   157  	return swag.WriteJSON(m)
   158  }
   159  
   160  // UnmarshalBinary interface implementation
   161  func (m *TraceTo) UnmarshalBinary(b []byte) error {
   162  	var res TraceTo
   163  	if err := swag.ReadJSON(b, &res); err != nil {
   164  		return err
   165  	}
   166  	*m = res
   167  	return nil
   168  }