Skip to content

Commit 445eb1f

Browse files
committed
Add utils to translate custom types
1 parent aa8579c commit 445eb1f

File tree

4 files changed

+345
-355
lines changed

4 files changed

+345
-355
lines changed

apis/v1alpha2/helper.go

-177
This file was deleted.

apis/v1alpha2/util/translator/shared_types.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.
@@ -25,3 +25,161 @@ 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+
func ListenerHostnameToPtr(host string) *gatewayv1a2.Hostname {
48+
h := *gatewayv1a2.Hostname(host)
49+
return &h
50+
}
51+
52+
func ListenerHostnameFromPtr(name *Hostname) string {
53+
hostName := string(*name)
54+
return hostName
55+
}
56+
57+
func PreciseHostnameToPtr(host string) *PreciseHostname {
58+
h := PreciseHostname(host)
59+
return &h
60+
}
61+
62+
func PreciseHostnameFromPtr(name *PreciseHostname) string {
63+
prechostName := string(*name)
64+
return prechostName
65+
}
66+
67+
func GroupToPtr(group string) *Group {
68+
gwGroup := Group(group)
69+
return &gwGroup
70+
}
71+
72+
func GroupFromPtr(name *Group) string {
73+
groupStr := string(*name)
74+
return groupStr
75+
}
76+
77+
func KindToPtr(kind string) *Kind {
78+
gwKind := Kind(kind)
79+
return &gwKind
80+
}
81+
82+
func KindFromPtr(name *Kind) string {
83+
kindStr := string(*name)
84+
return kindStr
85+
}
86+
87+
func NamespaceToPtr(namespace string) *Namespace {
88+
gwNamespace := Namespace(namespace)
89+
return &gwNamespace
90+
}
91+
92+
func NamespaceFromPtr(name *Namespace) string {
93+
namespace := string(*name)
94+
return namespace
95+
}
96+
97+
func ObjectNameToPtr(name string) *ObjectName {
98+
objectName := ObjectName(name)
99+
return &objectName
100+
}
101+
102+
func ObjectNameFromPtr(name *ObjectName) string {
103+
objname := string(*name)
104+
return objname
105+
}
106+
107+
func GatewayControllerToPtr(name string) *GatewayController {
108+
gwCtrl := GatewayController(name)
109+
return &gwCtrl
110+
}
111+
112+
func GatewayControllerFromPtr(name *GatewayController) string {
113+
gw := string(*name)
114+
return gw
115+
}
116+
117+
func AnnotationKeyToPtr(name string) *AnnotationKey {
118+
key := AnnotationKey(name)
119+
return &key
120+
}
121+
122+
func AnnotationKeyFromPtr(name *AnnotationKey) string {
123+
key := string(*name)
124+
return key
125+
}
126+
127+
func AnnotationValueToPtr(name string) *AnnotationValue {
128+
val := AnnotationValue(name)
129+
return &val
130+
}
131+
132+
func AnnotationValueFromPtr(name *AnnotationValue) string {
133+
val := string(*name)
134+
return val
135+
}
136+
137+
func AddressTypeToPtr(name string) *AddressType {
138+
addr := AddressType(name)
139+
return &addr
140+
}
141+
142+
func AddressTypeFromPtr(name *AddressType) string {
143+
val := string(*name)
144+
return val
145+
}
146+
147+
func RouteConditionTypeToPtr(name string) *RouteConditionType {
148+
str := RouteConditionType(name)
149+
return &str
150+
}
151+
152+
func RouteConditionTypeFromPtr(name *RouteConditionType) string {
153+
val := string(*name)
154+
return val
155+
}
156+
157+
func RouteConditionReasonToPtr(name string) *RouteConditionReason {
158+
str := RouteConditionReason(name)
159+
return &str
160+
}
161+
162+
func RouteConditionReasonFromPtr(name *RouteConditionType) string {
163+
val := string(*name)
164+
return val
165+
}
166+
167+
func ProtocolTypeToPtr(name string) *ProtocolType {
168+
proto := ProtocolType(name)
169+
return &proto
170+
}
171+
172+
func ProtocolTypeFromPtr(name *ProtocolType) string {
173+
val := string(*name)
174+
return val
175+
}
176+
177+
func TLSModeTypePtr(name string) *TLSModeType {
178+
tls := TLSModeType(name)
179+
return &tls
180+
}
181+
182+
func TLSModeTypeFromPtr(name *TLSModeType) string {
183+
val := string(*name)
184+
return val
185+
}

0 commit comments

Comments
 (0)