Skip to content

Commit b1640c1

Browse files
committed
Add utils to translate custom types
Add utils to translate custom types
1 parent 66ee517 commit b1640c1

File tree

2 files changed

+345
-1
lines changed

2 files changed

+345
-1
lines changed

apis/v1alpha2/validation/util/utils.go

+159-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2021 The Kubernetes Authors.
2+
Copyright 2022 The Kubernetes Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -31,3 +31,161 @@ func PortNumberPtr(p int) *gatewayv1a2.PortNumber {
3131
result := gatewayv1a2.PortNumber(p)
3232
return &result
3333
}
34+
35+
// PortNumberInt32 translates reference value of ptr to Int32
36+
func PortNumberInt32(name *gatewayv1a2.PortNumber) int32 {
37+
portNum := int32(*name)
38+
return portNum
39+
}
40+
41+
// SectionNamePtr translates an int to a *SectionName
42+
func SectionNamePtr(sectionName string) *gatewayv1a2.SectionName {
43+
gwSectionName := gatewayv1a2.SectionName(sectionName)
44+
return &gwSectionName
45+
}
46+
47+
// SectionNameStr translates reference value of ptr to string
48+
func SectionNameStr(name *gatewayv1a2.SectionName) string {
49+
sectionName := string(*name)
50+
return sectionName
51+
}
52+
53+
func ListenerHostnameToPtr(host string) *gatewayv1a2.Hostname {
54+
h := *gatewayv1a2.Hostname(host)
55+
return &h
56+
}
57+
58+
func ListenerHostnameFromPtr(name *Hostname) string {
59+
hostName := string(*name)
60+
return hostName
61+
}
62+
63+
func PreciseHostnameToPtr(host string) *PreciseHostname {
64+
h := PreciseHostname(host)
65+
return &h
66+
}
67+
68+
func PreciseHostnameFromPtr(name *PreciseHostname) string {
69+
prechostName := string(*name)
70+
return prechostName
71+
}
72+
73+
func GroupToPtr(group string) *Group {
74+
gwGroup := Group(group)
75+
return &gwGroup
76+
}
77+
78+
func GroupFromPtr(name *Group) string {
79+
groupStr := string(*name)
80+
return groupStr
81+
}
82+
83+
func KindToPtr(kind string) *Kind {
84+
gwKind := Kind(kind)
85+
return &gwKind
86+
}
87+
88+
func KindFromPtr(name *Kind) string {
89+
kindStr := string(*name)
90+
return kindStr
91+
}
92+
93+
func NamespaceToPtr(namespace string) *Namespace {
94+
gwNamespace := Namespace(namespace)
95+
return &gwNamespace
96+
}
97+
98+
func NamespaceFromPtr(name *Namespace) string {
99+
namespace := string(*name)
100+
return namespace
101+
}
102+
103+
func ObjectNameToPtr(name string) *ObjectName {
104+
objectName := ObjectName(name)
105+
return &objectName
106+
}
107+
108+
func ObjectNameFromPtr(name *ObjectName) string {
109+
objname := string(*name)
110+
return objname
111+
}
112+
113+
func GatewayControllerToPtr(name string) *GatewayController {
114+
gwCtrl := GatewayController(name)
115+
return &gwCtrl
116+
}
117+
118+
func GatewayControllerFromPtr(name *GatewayController) string {
119+
gw := string(*name)
120+
return gw
121+
}
122+
123+
func AnnotationKeyToPtr(name string) *AnnotationKey {
124+
key := AnnotationKey(name)
125+
return &key
126+
}
127+
128+
func AnnotationKeyFromPtr(name *AnnotationKey) string {
129+
key := string(*name)
130+
return key
131+
}
132+
133+
func AnnotationValueToPtr(name string) *AnnotationValue {
134+
val := AnnotationValue(name)
135+
return &val
136+
}
137+
138+
func AnnotationValueFromPtr(name *AnnotationValue) string {
139+
val := string(*name)
140+
return val
141+
}
142+
143+
func AddressTypeToPtr(name string) *AddressType {
144+
addr := AddressType(name)
145+
return &addr
146+
}
147+
148+
func AddressTypeFromPtr(name *AddressType) string {
149+
val := string(*name)
150+
return val
151+
}
152+
153+
func RouteConditionTypeToPtr(name string) *RouteConditionType {
154+
str := RouteConditionType(name)
155+
return &str
156+
}
157+
158+
func RouteConditionTypeFromPtr(name *RouteConditionType) string {
159+
val := string(*name)
160+
return val
161+
}
162+
163+
func RouteConditionReasonToPtr(name string) *RouteConditionReason {
164+
str := RouteConditionReason(name)
165+
return &str
166+
}
167+
168+
func RouteConditionReasonFromPtr(name *RouteConditionType) string {
169+
val := string(*name)
170+
return val
171+
}
172+
173+
func ProtocolTypeToPtr(name string) *ProtocolType {
174+
proto := ProtocolType(name)
175+
return &proto
176+
}
177+
178+
func ProtocolTypeFromPtr(name *ProtocolType) string {
179+
val := string(*name)
180+
return val
181+
}
182+
183+
func TLSModeTypePtr(name string) *TLSModeType {
184+
tls := TLSModeType(name)
185+
return &tls
186+
}
187+
188+
func TLSModeTypeFromPtr(name *TLSModeType) string {
189+
val := string(*name)
190+
return val
191+
}

apis/v1beta1/validation/util/utils.go

+186
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,189 @@ func PortNumberPtr(p int) *gatewayv1b1.PortNumber {
3131
result := gatewayv1b1.PortNumber(p)
3232
return &result
3333
}
34+
35+
// PortNumberInt32 translates reference value of ptr to Int32
36+
func PortNumberInt32(name *gatewayv1b1.PortNumber) int32 {
37+
portNum := int32(*name)
38+
return portNum
39+
}
40+
41+
// SectionNamePtr translates an int to a *SectionName
42+
func SectionNamePtr(sectionName string) *gatewayv1b1.SectionName {
43+
gwSectionName := gatewayv1b1.SectionName(sectionName)
44+
return &gwSectionName
45+
}
46+
47+
// SectionNameStr translates reference value of ptr to string
48+
func SectionNameStr(name *gatewayv1b1.SectionName) string {
49+
sectionName := string(*name)
50+
return sectionName
51+
}
52+
53+
// HostnamePtr translates an int to a *Hostname
54+
func HostnamePtr(host string) *gatewayv1b1.Hostname {
55+
h := gatewayv1b1.Hostname(host)
56+
return &h
57+
}
58+
59+
// HostnameStr translates reference value of ptr to string
60+
func HostnameStr(name *gatewayv1b1.Hostname) string {
61+
hostName := string(*name)
62+
return hostName
63+
}
64+
65+
// PreciseHostnamePtr translates an int to a *PreciseHostname
66+
func PreciseHostnamePtr(host string) *gatewayv1b1.PreciseHostname {
67+
h := gatewayv1b1.PreciseHostname(host)
68+
return &h
69+
}
70+
71+
// PreciseHostnameStr translates reference value of ptr to string
72+
func PreciseHostnameStr(name *gatewayv1b1.PreciseHostname) string {
73+
prechostName := string(*name)
74+
return prechostName
75+
}
76+
77+
// GroupPtr translates an int to a *Group
78+
func GroupPtr(group string) *gatewayv1b1.Group {
79+
gwGroup := gatewayv1b1.Group(group)
80+
return &gwGroup
81+
}
82+
83+
// GroupStr translates reference value of ptr to string
84+
func GroupStr(name *gatewayv1b1.Group) string {
85+
groupStr := string(*name)
86+
return groupStr
87+
}
88+
89+
// KindPtr translates an int to a *Kind
90+
func KindPtr(kind string) *gatewayv1b1.Kind {
91+
gwKind := gatewayv1b1.Kind(kind)
92+
return &gwKind
93+
}
94+
95+
// KindStr translates reference value of ptr to string
96+
func KindStr(name *gatewayv1b1.Kind) string {
97+
kindStr := string(*name)
98+
return kindStr
99+
}
100+
101+
// NamespacePtr translates an int to a *Namespace
102+
func NamespacePtr(namespace string) *gatewayv1b1.Namespace {
103+
gwNamespace := gatewayv1b1.Namespace(namespace)
104+
return &gwNamespace
105+
}
106+
107+
// NamespaceStr translates reference value of ptr to string
108+
func NamespaceStr(name *gatewayv1b1.Namespace) string {
109+
namespace := string(*name)
110+
return namespace
111+
}
112+
113+
// ObjectNamePtr translates an int to a *ObjectName
114+
func ObjectNamePtr(name string) *gatewayv1b1.ObjectName {
115+
objectName := gatewayv1b1.ObjectName(name)
116+
return &objectName
117+
}
118+
119+
// ObjectNameStr translates reference value of ptr to string
120+
func ObjectNameStr(name *gatewayv1b1.ObjectName) string {
121+
objname := string(*name)
122+
return objname
123+
}
124+
125+
// GatewayControllerPtr translates an int to a *GatewayController
126+
func GatewayControllerPtr(name string) *gatewayv1b1.GatewayController {
127+
gwCtrl := gatewayv1b1.GatewayController(name)
128+
return &gwCtrl
129+
}
130+
131+
// GatewayControllerStr translates reference value of ptr to string
132+
func GatewayControllerStr(name *gatewayv1b1.GatewayController) string {
133+
gw := string(*name)
134+
return gw
135+
}
136+
137+
// AnnotationKeyPtr translates an int to a *AnnotationKey
138+
func AnnotationKeyPtr(name string) *gatewayv1b1.AnnotationKey {
139+
key := gatewayv1b1.AnnotationKey(name)
140+
return &key
141+
}
142+
143+
// AnnotationKeyStr translates reference value of ptr to string
144+
func AnnotationKeyStr(name *gatewayv1b1.AnnotationKey) string {
145+
key := string(*name)
146+
return key
147+
}
148+
149+
// AnnotationValuePtr translates an int to a *AnnotationValue
150+
func AnnotationValuePtr(name string) *gatewayv1b1.AnnotationValue {
151+
val := gatewayv1b1.AnnotationValue(name)
152+
return &val
153+
}
154+
155+
// AnnotationValueStr translates reference value of ptr to string
156+
func AnnotationValueStr(name *gatewayv1b1.AnnotationValue) string {
157+
val := string(*name)
158+
return val
159+
}
160+
161+
// AddressTypePtr translates an int to a *AddressType
162+
func AddressTypePtr(name string) *gatewayv1b1.AddressType {
163+
addr := gatewayv1b1.AddressType(name)
164+
return &addr
165+
}
166+
167+
// AddressTypeStr translates reference value of ptr to string
168+
func AddressTypeStr(name *gatewayv1b1.AddressType) string {
169+
val := string(*name)
170+
return val
171+
}
172+
173+
// RouteConditionTypePtr translates an int to a *RouteConditionType
174+
func RouteConditionTypePtr(name string) *gatewayv1b1.RouteConditionType {
175+
str := gatewayv1b1.RouteConditionType(name)
176+
return &str
177+
}
178+
179+
// RouteConditionTypeStr translates reference value of ptr to string
180+
func RouteConditionTypeStr(name *gatewayv1b1.RouteConditionType) string {
181+
val := string(*name)
182+
return val
183+
}
184+
185+
// RouteConditionReasonPtr translates an int to a *RouteConditionReason
186+
func RouteConditionReasonPtr(name string) *gatewayv1b1.RouteConditionReason {
187+
str := gatewayv1b1.RouteConditionReason(name)
188+
return &str
189+
}
190+
191+
// RouteConditionReasonStr translates reference value of ptr to string
192+
func RouteConditionReasonStr(name *gatewayv1b1.RouteConditionType) string {
193+
val := string(*name)
194+
return val
195+
}
196+
197+
// ProtocolTypePtr translates an int to a *ProtocolType
198+
func ProtocolTypePtr(name string) *gatewayv1b1.ProtocolType {
199+
proto := gatewayv1b1.ProtocolType(name)
200+
return &proto
201+
}
202+
203+
// ProtocolTypeStr translates reference value of ptr to string
204+
func ProtocolTypeStr(name *gatewayv1b1.ProtocolType) string {
205+
val := string(*name)
206+
return val
207+
}
208+
209+
// TLSModeTypePtr translates an int to a *TLSModeType
210+
func TLSModeTypePtr(name string) *gatewayv1b1.TLSModeType {
211+
tls := gatewayv1b1.TLSModeType(name)
212+
return &tls
213+
}
214+
215+
// TLSModeTypeStr translates reference value of ptr to string
216+
func TLSModeTypeStr(name *gatewayv1b1.TLSModeType) string {
217+
val := string(*name)
218+
return val
219+
}

0 commit comments

Comments
 (0)