Skip to content

Commit 9138381

Browse files
authored
Merge pull request #1352 from abhijit-dev82/translation-fix
Add utils to translate custom types
2 parents f8b1187 + a1c3231 commit 9138381

File tree

2 files changed

+372
-0
lines changed

2 files changed

+372
-0
lines changed

apis/v1alpha2/util/translator/shared_types.go

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

apis/v1beta1/util/translator/shared_types.go

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

0 commit comments

Comments
 (0)