github.com/cilium/cilium@v1.16.2/api/v1/models/port.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  // Port Layer 4 port / protocol pair
    22  //
    23  // +deepequal-gen=true
    24  //
    25  // swagger:model Port
    26  type Port struct {
    27  
    28  	// Optional layer 4 port name
    29  	Name string `json:"name,omitempty"`
    30  
    31  	// Layer 4 port number
    32  	Port uint16 `json:"port,omitempty"`
    33  
    34  	// Layer 4 protocol
    35  	// Enum: [TCP UDP SCTP ICMP ICMPV6 ANY]
    36  	Protocol string `json:"protocol,omitempty"`
    37  }
    38  
    39  // Validate validates this port
    40  func (m *Port) Validate(formats strfmt.Registry) error {
    41  	var res []error
    42  
    43  	if err := m.validateProtocol(formats); err != nil {
    44  		res = append(res, err)
    45  	}
    46  
    47  	if len(res) > 0 {
    48  		return errors.CompositeValidationError(res...)
    49  	}
    50  	return nil
    51  }
    52  
    53  var portTypeProtocolPropEnum []interface{}
    54  
    55  func init() {
    56  	var res []string
    57  	if err := json.Unmarshal([]byte(`["TCP","UDP","SCTP","ICMP","ICMPV6","ANY"]`), &res); err != nil {
    58  		panic(err)
    59  	}
    60  	for _, v := range res {
    61  		portTypeProtocolPropEnum = append(portTypeProtocolPropEnum, v)
    62  	}
    63  }
    64  
    65  const (
    66  
    67  	// PortProtocolTCP captures enum value "TCP"
    68  	PortProtocolTCP string = "TCP"
    69  
    70  	// PortProtocolUDP captures enum value "UDP"
    71  	PortProtocolUDP string = "UDP"
    72  
    73  	// PortProtocolSCTP captures enum value "SCTP"
    74  	PortProtocolSCTP string = "SCTP"
    75  
    76  	// PortProtocolICMP captures enum value "ICMP"
    77  	PortProtocolICMP string = "ICMP"
    78  
    79  	// PortProtocolICMPV6 captures enum value "ICMPV6"
    80  	PortProtocolICMPV6 string = "ICMPV6"
    81  
    82  	// PortProtocolANY captures enum value "ANY"
    83  	PortProtocolANY string = "ANY"
    84  )
    85  
    86  // prop value enum
    87  func (m *Port) validateProtocolEnum(path, location string, value string) error {
    88  	if err := validate.EnumCase(path, location, value, portTypeProtocolPropEnum, true); err != nil {
    89  		return err
    90  	}
    91  	return nil
    92  }
    93  
    94  func (m *Port) validateProtocol(formats strfmt.Registry) error {
    95  	if swag.IsZero(m.Protocol) { // not required
    96  		return nil
    97  	}
    98  
    99  	// value enum
   100  	if err := m.validateProtocolEnum("protocol", "body", m.Protocol); err != nil {
   101  		return err
   102  	}
   103  
   104  	return nil
   105  }
   106  
   107  // ContextValidate validates this port based on context it is used
   108  func (m *Port) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   109  	return nil
   110  }
   111  
   112  // MarshalBinary interface implementation
   113  func (m *Port) MarshalBinary() ([]byte, error) {
   114  	if m == nil {
   115  		return nil, nil
   116  	}
   117  	return swag.WriteJSON(m)
   118  }
   119  
   120  // UnmarshalBinary interface implementation
   121  func (m *Port) UnmarshalBinary(b []byte) error {
   122  	var res Port
   123  	if err := swag.ReadJSON(b, &res); err != nil {
   124  		return err
   125  	}
   126  	*m = res
   127  	return nil
   128  }