Skip to content

Add utils to translate custom types #1352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 186 additions & 0 deletions apis/v1alpha2/util/translator/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,189 @@ func PortNumberPtr(p int) *gatewayv1a2.PortNumber {
result := gatewayv1a2.PortNumber(p)
return &result
}

// PortNumberInt32 translates reference value of ptr to Int32
func PortNumberInt32(name *gatewayv1a2.PortNumber) int32 {
portNum := int32(*name)
return portNum
}

// SectionNamePtr translates an int to a *SectionName
func SectionNamePtr(sectionName string) *gatewayv1a2.SectionName {
gwSectionName := gatewayv1a2.SectionName(sectionName)
return &gwSectionName
}

// SectionNameStr translates reference value of ptr to string
func SectionNameStr(name *gatewayv1a2.SectionName) string {
sectionName := string(*name)
return sectionName
}

// HostnamePtr translates an int to a *Hostname
func HostnamePtr(host string) *gatewayv1a2.Hostname {
h := gatewayv1a2.Hostname(host)
return &h
}

// HostnameStr translates reference value of ptr to string
func HostnameStr(name *gatewayv1a2.Hostname) string {
hostName := string(*name)
return hostName
}

// PreciseHostnamePtr translates an int to a *PreciseHostname
func PreciseHostnamePtr(host string) *gatewayv1a2.PreciseHostname {
h := gatewayv1a2.PreciseHostname(host)
return &h
}

// PreciseHostnameStr translates reference value of ptr to string
func PreciseHostnameStr(name *gatewayv1a2.PreciseHostname) string {
prechostName := string(*name)
return prechostName
}

// GroupPtr translates an int to a *Group
func GroupPtr(group string) *gatewayv1a2.Group {
gwGroup := gatewayv1a2.Group(group)
return &gwGroup
}

// GroupStr translates reference value of ptr to string
func GroupStr(name *gatewayv1a2.Group) string {
groupStr := string(*name)
return groupStr
}

// KindPtr translates an int to a *Kind
func KindPtr(kind string) *gatewayv1a2.Kind {
gwKind := gatewayv1a2.Kind(kind)
return &gwKind
}

// KindStr translates reference value of ptr to string
func KindStr(name *gatewayv1a2.Kind) string {
kindStr := string(*name)
return kindStr
}

// NamespacePtr translates an int to a *Namespace
func NamespacePtr(namespace string) *gatewayv1a2.Namespace {
gwNamespace := gatewayv1a2.Namespace(namespace)
return &gwNamespace
}

// NamespaceStr translates reference value of ptr to string
func NamespaceStr(name *gatewayv1a2.Namespace) string {
namespace := string(*name)
return namespace
}

// ObjectNamePtr translates an int to a *ObjectName
func ObjectNamePtr(name string) *gatewayv1a2.ObjectName {
objectName := gatewayv1a2.ObjectName(name)
return &objectName
}

// ObjectNameStr translates reference value of ptr to string
func ObjectNameStr(name *gatewayv1a2.ObjectName) string {
objname := string(*name)
return objname
}

// GatewayControllerPtr translates an int to a *GatewayController
func GatewayControllerPtr(name string) *gatewayv1a2.GatewayController {
gwCtrl := gatewayv1a2.GatewayController(name)
return &gwCtrl
}

// GatewayControllerStr translates reference value of ptr to string
func GatewayControllerStr(name *gatewayv1a2.GatewayController) string {
gw := string(*name)
return gw
}

// AnnotationKeyPtr translates an int to a *AnnotationKey
func AnnotationKeyPtr(name string) *gatewayv1a2.AnnotationKey {
key := gatewayv1a2.AnnotationKey(name)
return &key
}

// AnnotationKeyStr translates reference value of ptr to string
func AnnotationKeyStr(name *gatewayv1a2.AnnotationKey) string {
key := string(*name)
return key
}

// AnnotationValuePtr translates an int to a *AnnotationValue
func AnnotationValuePtr(name string) *gatewayv1a2.AnnotationValue {
val := gatewayv1a2.AnnotationValue(name)
return &val
}

// AnnotationValueStr translates reference value of ptr to string
func AnnotationValueStr(name *gatewayv1a2.AnnotationValue) string {
val := string(*name)
return val
}

// AddressTypePtr translates an int to a *AddressType
func AddressTypePtr(name string) *gatewayv1a2.AddressType {
addr := gatewayv1a2.AddressType(name)
return &addr
}

// AddressTypeStr translates reference value of ptr to string
func AddressTypeStr(name *gatewayv1a2.AddressType) string {
val := string(*name)
return val
}

// RouteConditionTypePtr translates an int to a *RouteConditionType
func RouteConditionTypePtr(name string) *gatewayv1a2.RouteConditionType {
str := gatewayv1a2.RouteConditionType(name)
return &str
}

// RouteConditionTypeStr translates reference value of ptr to string
func RouteConditionTypeStr(name *gatewayv1a2.RouteConditionType) string {
val := string(*name)
return val
}

// RouteConditionReasonPtr translates an int to a *RouteConditionReason
func RouteConditionReasonPtr(name string) *gatewayv1a2.RouteConditionReason {
str := gatewayv1a2.RouteConditionReason(name)
return &str
}

// RouteConditionReasonStr translates reference value of ptr to string
func RouteConditionReasonStr(name *gatewayv1a2.RouteConditionType) string {
val := string(*name)
return val
}

// ProtocolTypePtr translates an int to a *ProtocolType
func ProtocolTypePtr(name string) *gatewayv1a2.ProtocolType {
proto := gatewayv1a2.ProtocolType(name)
return &proto
}

// ProtocolTypeStr translates reference value of ptr to string
func ProtocolTypeStr(name *gatewayv1a2.ProtocolType) string {
val := string(*name)
return val
}

// TLSModeTypePtr translates an int to a *TLSModeType
func TLSModeTypePtr(name string) *gatewayv1a2.TLSModeType {
tls := gatewayv1a2.TLSModeType(name)
return &tls
}

// TLSModeTypeStr translates reference value of ptr to string
func TLSModeTypeStr(name *gatewayv1a2.TLSModeType) string {
val := string(*name)
return val
}
186 changes: 186 additions & 0 deletions apis/v1beta1/util/translator/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,189 @@ func PortNumberPtr(p int) *gatewayv1b1.PortNumber {
result := gatewayv1b1.PortNumber(p)
return &result
}

// PortNumberInt32 translates reference value of ptr to Int32
func PortNumberInt32(name *gatewayv1b1.PortNumber) int32 {
portNum := int32(*name)
return portNum
}

// SectionNamePtr translates an int to a *SectionName
func SectionNamePtr(sectionName string) *gatewayv1b1.SectionName {
gwSectionName := gatewayv1b1.SectionName(sectionName)
return &gwSectionName
}

// SectionNameStr translates reference value of ptr to string
func SectionNameStr(name *gatewayv1b1.SectionName) string {
sectionName := string(*name)
return sectionName
}

// HostnamePtr translates an int to a *Hostname
func HostnamePtr(host string) *gatewayv1b1.Hostname {
h := gatewayv1b1.Hostname(host)
return &h
}

// HostnameStr translates reference value of ptr to string
func HostnameStr(name *gatewayv1b1.Hostname) string {
hostName := string(*name)
return hostName
}

// PreciseHostnamePtr translates an int to a *PreciseHostname
func PreciseHostnamePtr(host string) *gatewayv1b1.PreciseHostname {
h := gatewayv1b1.PreciseHostname(host)
return &h
}

// PreciseHostnameStr translates reference value of ptr to string
func PreciseHostnameStr(name *gatewayv1b1.PreciseHostname) string {
prechostName := string(*name)
return prechostName
}

// GroupPtr translates an int to a *Group
func GroupPtr(group string) *gatewayv1b1.Group {
gwGroup := gatewayv1b1.Group(group)
return &gwGroup
}

// GroupStr translates reference value of ptr to string
func GroupStr(name *gatewayv1b1.Group) string {
groupStr := string(*name)
return groupStr
}

// KindPtr translates an int to a *Kind
func KindPtr(kind string) *gatewayv1b1.Kind {
gwKind := gatewayv1b1.Kind(kind)
return &gwKind
}

// KindStr translates reference value of ptr to string
func KindStr(name *gatewayv1b1.Kind) string {
kindStr := string(*name)
return kindStr
}

// NamespacePtr translates an int to a *Namespace
func NamespacePtr(namespace string) *gatewayv1b1.Namespace {
gwNamespace := gatewayv1b1.Namespace(namespace)
return &gwNamespace
}

// NamespaceStr translates reference value of ptr to string
func NamespaceStr(name *gatewayv1b1.Namespace) string {
namespace := string(*name)
return namespace
}

// ObjectNamePtr translates an int to a *ObjectName
func ObjectNamePtr(name string) *gatewayv1b1.ObjectName {
objectName := gatewayv1b1.ObjectName(name)
return &objectName
}

// ObjectNameStr translates reference value of ptr to string
func ObjectNameStr(name *gatewayv1b1.ObjectName) string {
objname := string(*name)
return objname
}

// GatewayControllerPtr translates an int to a *GatewayController
func GatewayControllerPtr(name string) *gatewayv1b1.GatewayController {
gwCtrl := gatewayv1b1.GatewayController(name)
return &gwCtrl
}

// GatewayControllerStr translates reference value of ptr to string
func GatewayControllerStr(name *gatewayv1b1.GatewayController) string {
gw := string(*name)
return gw
}

// AnnotationKeyPtr translates an int to a *AnnotationKey
func AnnotationKeyPtr(name string) *gatewayv1b1.AnnotationKey {
key := gatewayv1b1.AnnotationKey(name)
return &key
}

// AnnotationKeyStr translates reference value of ptr to string
func AnnotationKeyStr(name *gatewayv1b1.AnnotationKey) string {
key := string(*name)
return key
}

// AnnotationValuePtr translates an int to a *AnnotationValue
func AnnotationValuePtr(name string) *gatewayv1b1.AnnotationValue {
val := gatewayv1b1.AnnotationValue(name)
return &val
}

// AnnotationValueStr translates reference value of ptr to string
func AnnotationValueStr(name *gatewayv1b1.AnnotationValue) string {
val := string(*name)
return val
}

// AddressTypePtr translates an int to a *AddressType
func AddressTypePtr(name string) *gatewayv1b1.AddressType {
addr := gatewayv1b1.AddressType(name)
return &addr
}

// AddressTypeStr translates reference value of ptr to string
func AddressTypeStr(name *gatewayv1b1.AddressType) string {
val := string(*name)
return val
}

// RouteConditionTypePtr translates an int to a *RouteConditionType
func RouteConditionTypePtr(name string) *gatewayv1b1.RouteConditionType {
str := gatewayv1b1.RouteConditionType(name)
return &str
}

// RouteConditionTypeStr translates reference value of ptr to string
func RouteConditionTypeStr(name *gatewayv1b1.RouteConditionType) string {
val := string(*name)
return val
}

// RouteConditionReasonPtr translates an int to a *RouteConditionReason
func RouteConditionReasonPtr(name string) *gatewayv1b1.RouteConditionReason {
str := gatewayv1b1.RouteConditionReason(name)
return &str
}

// RouteConditionReasonStr translates reference value of ptr to string
func RouteConditionReasonStr(name *gatewayv1b1.RouteConditionType) string {
val := string(*name)
return val
}

// ProtocolTypePtr translates an int to a *ProtocolType
func ProtocolTypePtr(name string) *gatewayv1b1.ProtocolType {
proto := gatewayv1b1.ProtocolType(name)
return &proto
}

// ProtocolTypeStr translates reference value of ptr to string
func ProtocolTypeStr(name *gatewayv1b1.ProtocolType) string {
val := string(*name)
return val
}

// TLSModeTypePtr translates an int to a *TLSModeType
func TLSModeTypePtr(name string) *gatewayv1b1.TLSModeType {
tls := gatewayv1b1.TLSModeType(name)
return &tls
}

// TLSModeTypeStr translates reference value of ptr to string
func TLSModeTypeStr(name *gatewayv1b1.TLSModeType) string {
val := string(*name)
return val
}