github.com/kubearmor/cilium@v1.6.12/api/v1/models/port.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 "encoding/json" 10 11 strfmt "github.com/go-openapi/strfmt" 12 13 "github.com/go-openapi/errors" 14 "github.com/go-openapi/swag" 15 "github.com/go-openapi/validate" 16 ) 17 18 // Port Layer 4 port / protocol pair 19 // swagger:model Port 20 type Port struct { 21 22 // Layer 4 port number 23 Port uint16 `json:"port,omitempty"` 24 25 // Layer 4 protocol 26 // Enum: [TCP UDP ANY] 27 Protocol string `json:"protocol,omitempty"` 28 } 29 30 // Validate validates this port 31 func (m *Port) Validate(formats strfmt.Registry) error { 32 var res []error 33 34 if err := m.validateProtocol(formats); err != nil { 35 res = append(res, err) 36 } 37 38 if len(res) > 0 { 39 return errors.CompositeValidationError(res...) 40 } 41 return nil 42 } 43 44 var portTypeProtocolPropEnum []interface{} 45 46 func init() { 47 var res []string 48 if err := json.Unmarshal([]byte(`["TCP","UDP","ANY"]`), &res); err != nil { 49 panic(err) 50 } 51 for _, v := range res { 52 portTypeProtocolPropEnum = append(portTypeProtocolPropEnum, v) 53 } 54 } 55 56 const ( 57 58 // PortProtocolTCP captures enum value "TCP" 59 PortProtocolTCP string = "TCP" 60 61 // PortProtocolUDP captures enum value "UDP" 62 PortProtocolUDP string = "UDP" 63 64 // PortProtocolANY captures enum value "ANY" 65 PortProtocolANY string = "ANY" 66 ) 67 68 // prop value enum 69 func (m *Port) validateProtocolEnum(path, location string, value string) error { 70 if err := validate.Enum(path, location, value, portTypeProtocolPropEnum); err != nil { 71 return err 72 } 73 return nil 74 } 75 76 func (m *Port) validateProtocol(formats strfmt.Registry) error { 77 78 if swag.IsZero(m.Protocol) { // not required 79 return nil 80 } 81 82 // value enum 83 if err := m.validateProtocolEnum("protocol", "body", m.Protocol); err != nil { 84 return err 85 } 86 87 return nil 88 } 89 90 // MarshalBinary interface implementation 91 func (m *Port) MarshalBinary() ([]byte, error) { 92 if m == nil { 93 return nil, nil 94 } 95 return swag.WriteJSON(m) 96 } 97 98 // UnmarshalBinary interface implementation 99 func (m *Port) UnmarshalBinary(b []byte) error { 100 var res Port 101 if err := swag.ReadJSON(b, &res); err != nil { 102 return err 103 } 104 *m = res 105 return nil 106 }