github.com/cilium/cilium@v1.16.2/api/v1/models/frontend_mapping.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  // FrontendMapping Mapping of frontend to backend pods of an LRP
    21  //
    22  // swagger:model FrontendMapping
    23  type FrontendMapping struct {
    24  
    25  	// Pod backends of an LRP
    26  	Backends []*LRPBackend `json:"backends"`
    27  
    28  	// frontend address
    29  	FrontendAddress *FrontendAddress `json:"frontend-address,omitempty"`
    30  }
    31  
    32  // Validate validates this frontend mapping
    33  func (m *FrontendMapping) Validate(formats strfmt.Registry) error {
    34  	var res []error
    35  
    36  	if err := m.validateBackends(formats); err != nil {
    37  		res = append(res, err)
    38  	}
    39  
    40  	if err := m.validateFrontendAddress(formats); err != nil {
    41  		res = append(res, err)
    42  	}
    43  
    44  	if len(res) > 0 {
    45  		return errors.CompositeValidationError(res...)
    46  	}
    47  	return nil
    48  }
    49  
    50  func (m *FrontendMapping) validateBackends(formats strfmt.Registry) error {
    51  	if swag.IsZero(m.Backends) { // not required
    52  		return nil
    53  	}
    54  
    55  	for i := 0; i < len(m.Backends); i++ {
    56  		if swag.IsZero(m.Backends[i]) { // not required
    57  			continue
    58  		}
    59  
    60  		if m.Backends[i] != nil {
    61  			if err := m.Backends[i].Validate(formats); err != nil {
    62  				if ve, ok := err.(*errors.Validation); ok {
    63  					return ve.ValidateName("backends" + "." + strconv.Itoa(i))
    64  				} else if ce, ok := err.(*errors.CompositeError); ok {
    65  					return ce.ValidateName("backends" + "." + strconv.Itoa(i))
    66  				}
    67  				return err
    68  			}
    69  		}
    70  
    71  	}
    72  
    73  	return nil
    74  }
    75  
    76  func (m *FrontendMapping) validateFrontendAddress(formats strfmt.Registry) error {
    77  	if swag.IsZero(m.FrontendAddress) { // not required
    78  		return nil
    79  	}
    80  
    81  	if m.FrontendAddress != nil {
    82  		if err := m.FrontendAddress.Validate(formats); err != nil {
    83  			if ve, ok := err.(*errors.Validation); ok {
    84  				return ve.ValidateName("frontend-address")
    85  			} else if ce, ok := err.(*errors.CompositeError); ok {
    86  				return ce.ValidateName("frontend-address")
    87  			}
    88  			return err
    89  		}
    90  	}
    91  
    92  	return nil
    93  }
    94  
    95  // ContextValidate validate this frontend mapping based on the context it is used
    96  func (m *FrontendMapping) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
    97  	var res []error
    98  
    99  	if err := m.contextValidateBackends(ctx, formats); err != nil {
   100  		res = append(res, err)
   101  	}
   102  
   103  	if err := m.contextValidateFrontendAddress(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 *FrontendMapping) contextValidateBackends(ctx context.Context, formats strfmt.Registry) error {
   114  
   115  	for i := 0; i < len(m.Backends); i++ {
   116  
   117  		if m.Backends[i] != nil {
   118  
   119  			if swag.IsZero(m.Backends[i]) { // not required
   120  				return nil
   121  			}
   122  
   123  			if err := m.Backends[i].ContextValidate(ctx, formats); err != nil {
   124  				if ve, ok := err.(*errors.Validation); ok {
   125  					return ve.ValidateName("backends" + "." + strconv.Itoa(i))
   126  				} else if ce, ok := err.(*errors.CompositeError); ok {
   127  					return ce.ValidateName("backends" + "." + strconv.Itoa(i))
   128  				}
   129  				return err
   130  			}
   131  		}
   132  
   133  	}
   134  
   135  	return nil
   136  }
   137  
   138  func (m *FrontendMapping) contextValidateFrontendAddress(ctx context.Context, formats strfmt.Registry) error {
   139  
   140  	if m.FrontendAddress != nil {
   141  
   142  		if swag.IsZero(m.FrontendAddress) { // not required
   143  			return nil
   144  		}
   145  
   146  		if err := m.FrontendAddress.ContextValidate(ctx, formats); err != nil {
   147  			if ve, ok := err.(*errors.Validation); ok {
   148  				return ve.ValidateName("frontend-address")
   149  			} else if ce, ok := err.(*errors.CompositeError); ok {
   150  				return ce.ValidateName("frontend-address")
   151  			}
   152  			return err
   153  		}
   154  	}
   155  
   156  	return nil
   157  }
   158  
   159  // MarshalBinary interface implementation
   160  func (m *FrontendMapping) MarshalBinary() ([]byte, error) {
   161  	if m == nil {
   162  		return nil, nil
   163  	}
   164  	return swag.WriteJSON(m)
   165  }
   166  
   167  // UnmarshalBinary interface implementation
   168  func (m *FrontendMapping) UnmarshalBinary(b []byte) error {
   169  	var res FrontendMapping
   170  	if err := swag.ReadJSON(b, &res); err != nil {
   171  		return err
   172  	}
   173  	*m = res
   174  	return nil
   175  }