Skip to content

Commit 78ff80e

Browse files
committed
add conv pkg
This package contains convertors for every type defined in the strfmt main package. Each type has 2 convertors/helpers, to switch between their value and pointer type in a one-liner.
1 parent 0cb3db4 commit 78ff80e

File tree

8 files changed

+510
-0
lines changed

8 files changed

+510
-0
lines changed

conv/date.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package conv
2+
3+
import "github.com/go-openapi/strfmt"
4+
5+
// Date returns a pointer to of the Date value passed in.
6+
func Date(v strfmt.Date) *strfmt.Date {
7+
return &v
8+
}
9+
10+
// DateValue returns the value of the Date pointer passed in or
11+
// the default value if the pointer is nil.
12+
func DateValue(v *strfmt.Date) strfmt.Date {
13+
if v == nil {
14+
return strfmt.Date{}
15+
}
16+
17+
return *v
18+
}

conv/date_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package conv
2+
3+
import (
4+
"testing"
5+
"time"
6+
7+
"github.com/go-openapi/strfmt"
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestDateValue(t *testing.T) {
12+
assert.Equal(t, strfmt.Date{}, DateValue(nil))
13+
date := strfmt.Date(time.Now())
14+
assert.Equal(t, date, DateValue(&date))
15+
}

conv/default.go

Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
package conv
2+
3+
import (
4+
"github.com/go-openapi/strfmt"
5+
)
6+
7+
// Base64 returns a pointer to of the Base64 value passed in.
8+
func Base64(v strfmt.Base64) *strfmt.Base64 {
9+
return &v
10+
}
11+
12+
// Base64Value returns the value of the Base64 pointer passed in or
13+
// the default value if the pointer is nil.
14+
func Base64Value(v *strfmt.Base64) strfmt.Base64 {
15+
if v == nil {
16+
return nil
17+
}
18+
19+
return *v
20+
}
21+
22+
// URI returns a pointer to of the URI value passed in.
23+
func URI(v strfmt.URI) *strfmt.URI {
24+
return &v
25+
}
26+
27+
// URIValue returns the value of the URI pointer passed in or
28+
// the default value if the pointer is nil.
29+
func URIValue(v *strfmt.URI) strfmt.URI {
30+
if v == nil {
31+
return strfmt.URI("")
32+
}
33+
34+
return *v
35+
}
36+
37+
// Email returns a pointer to of the Email value passed in.
38+
func Email(v strfmt.Email) *strfmt.Email {
39+
return &v
40+
}
41+
42+
// EmailValue returns the value of the Email pointer passed in or
43+
// the default value if the pointer is nil.
44+
func EmailValue(v *strfmt.Email) strfmt.Email {
45+
if v == nil {
46+
return strfmt.Email("")
47+
}
48+
49+
return *v
50+
}
51+
52+
// Hostname returns a pointer to of the Hostname value passed in.
53+
func Hostname(v strfmt.Hostname) *strfmt.Hostname {
54+
return &v
55+
}
56+
57+
// HostnameValue returns the value of the Hostname pointer passed in or
58+
// the default value if the pointer is nil.
59+
func HostnameValue(v *strfmt.Hostname) strfmt.Hostname {
60+
if v == nil {
61+
return strfmt.Hostname("")
62+
}
63+
64+
return *v
65+
}
66+
67+
// IPv4 returns a pointer to of the IPv4 value passed in.
68+
func IPv4(v strfmt.IPv4) *strfmt.IPv4 {
69+
return &v
70+
}
71+
72+
// IPv4Value returns the value of the IPv4 pointer passed in or
73+
// the default value if the pointer is nil.
74+
func IPv4Value(v *strfmt.IPv4) strfmt.IPv4 {
75+
if v == nil {
76+
return strfmt.IPv4("")
77+
}
78+
79+
return *v
80+
}
81+
82+
// IPv6 returns a pointer to of the IPv6 value passed in.
83+
func IPv6(v strfmt.IPv6) *strfmt.IPv6 {
84+
return &v
85+
}
86+
87+
// IPv6Value returns the value of the IPv6 pointer passed in or
88+
// the default value if the pointer is nil.
89+
func IPv6Value(v *strfmt.IPv6) strfmt.IPv6 {
90+
if v == nil {
91+
return strfmt.IPv6("")
92+
}
93+
94+
return *v
95+
}
96+
97+
// MAC returns a pointer to of the MAC value passed in.
98+
func MAC(v strfmt.MAC) *strfmt.MAC {
99+
return &v
100+
}
101+
102+
// MACValue returns the value of the MAC pointer passed in or
103+
// the default value if the pointer is nil.
104+
func MACValue(v *strfmt.MAC) strfmt.MAC {
105+
if v == nil {
106+
return strfmt.MAC("")
107+
}
108+
109+
return *v
110+
}
111+
112+
// UUID returns a pointer to of the UUID value passed in.
113+
func UUID(v strfmt.UUID) *strfmt.UUID {
114+
return &v
115+
}
116+
117+
// UUIDValue returns the value of the UUID pointer passed in or
118+
// the default value if the pointer is nil.
119+
func UUIDValue(v *strfmt.UUID) strfmt.UUID {
120+
if v == nil {
121+
return strfmt.UUID("")
122+
}
123+
124+
return *v
125+
}
126+
127+
// UUID3 returns a pointer to of the UUID3 value passed in.
128+
func UUID3(v strfmt.UUID3) *strfmt.UUID3 {
129+
return &v
130+
}
131+
132+
// UUID3Value returns the value of the UUID3 pointer passed in or
133+
// the default value if the pointer is nil.
134+
func UUID3Value(v *strfmt.UUID3) strfmt.UUID3 {
135+
if v == nil {
136+
return strfmt.UUID3("")
137+
}
138+
139+
return *v
140+
}
141+
142+
// UUID4 returns a pointer to of the UUID4 value passed in.
143+
func UUID4(v strfmt.UUID4) *strfmt.UUID4 {
144+
return &v
145+
}
146+
147+
// UUID4Value returns the value of the UUID4 pointer passed in or
148+
// the default value if the pointer is nil.
149+
func UUID4Value(v *strfmt.UUID4) strfmt.UUID4 {
150+
if v == nil {
151+
return strfmt.UUID4("")
152+
}
153+
154+
return *v
155+
}
156+
157+
// UUID5 returns a pointer to of the UUID5 value passed in.
158+
func UUID5(v strfmt.UUID5) *strfmt.UUID5 {
159+
return &v
160+
}
161+
162+
// UUID5Value returns the value of the UUID5 pointer passed in or
163+
// the default value if the pointer is nil.
164+
func UUID5Value(v *strfmt.UUID5) strfmt.UUID5 {
165+
if v == nil {
166+
return strfmt.UUID5("")
167+
}
168+
169+
return *v
170+
}
171+
172+
// ISBN returns a pointer to of the ISBN value passed in.
173+
func ISBN(v strfmt.ISBN) *strfmt.ISBN {
174+
return &v
175+
}
176+
177+
// ISBNValue returns the value of the ISBN pointer passed in or
178+
// the default value if the pointer is nil.
179+
func ISBNValue(v *strfmt.ISBN) strfmt.ISBN {
180+
if v == nil {
181+
return strfmt.ISBN("")
182+
}
183+
184+
return *v
185+
}
186+
187+
// ISBN10 returns a pointer to of the ISBN10 value passed in.
188+
func ISBN10(v strfmt.ISBN10) *strfmt.ISBN10 {
189+
return &v
190+
}
191+
192+
// ISBN10Value returns the value of the ISBN10 pointer passed in or
193+
// the default value if the pointer is nil.
194+
func ISBN10Value(v *strfmt.ISBN10) strfmt.ISBN10 {
195+
if v == nil {
196+
return strfmt.ISBN10("")
197+
}
198+
199+
return *v
200+
}
201+
202+
// ISBN13 returns a pointer to of the ISBN13 value passed in.
203+
func ISBN13(v strfmt.ISBN13) *strfmt.ISBN13 {
204+
return &v
205+
}
206+
207+
// ISBN13Value returns the value of the ISBN13 pointer passed in or
208+
// the default value if the pointer is nil.
209+
func ISBN13Value(v *strfmt.ISBN13) strfmt.ISBN13 {
210+
if v == nil {
211+
return strfmt.ISBN13("")
212+
}
213+
214+
return *v
215+
}
216+
217+
// CreditCard returns a pointer to of the CreditCard value passed in.
218+
func CreditCard(v strfmt.CreditCard) *strfmt.CreditCard {
219+
return &v
220+
}
221+
222+
// CreditCardValue returns the value of the CreditCard pointer passed in or
223+
// the default value if the pointer is nil.
224+
func CreditCardValue(v *strfmt.CreditCard) strfmt.CreditCard {
225+
if v == nil {
226+
return strfmt.CreditCard("")
227+
}
228+
229+
return *v
230+
}
231+
232+
// SSN returns a pointer to of the SSN value passed in.
233+
func SSN(v strfmt.SSN) *strfmt.SSN {
234+
return &v
235+
}
236+
237+
// SSNValue returns the value of the SSN pointer passed in or
238+
// the default value if the pointer is nil.
239+
func SSNValue(v *strfmt.SSN) strfmt.SSN {
240+
if v == nil {
241+
return strfmt.SSN("")
242+
}
243+
244+
return *v
245+
}
246+
247+
// HexColor returns a pointer to of the HexColor value passed in.
248+
func HexColor(v strfmt.HexColor) *strfmt.HexColor {
249+
return &v
250+
}
251+
252+
// HexColorValue returns the value of the HexColor pointer passed in or
253+
// the default value if the pointer is nil.
254+
func HexColorValue(v *strfmt.HexColor) strfmt.HexColor {
255+
if v == nil {
256+
return strfmt.HexColor("")
257+
}
258+
259+
return *v
260+
}
261+
262+
// RGBColor returns a pointer to of the RGBColor value passed in.
263+
func RGBColor(v strfmt.RGBColor) *strfmt.RGBColor {
264+
return &v
265+
}
266+
267+
// RGBColorValue returns the value of the RGBColor pointer passed in or
268+
// the default value if the pointer is nil.
269+
func RGBColorValue(v *strfmt.RGBColor) strfmt.RGBColor {
270+
if v == nil {
271+
return strfmt.RGBColor("")
272+
}
273+
274+
return *v
275+
}
276+
277+
// Password returns a pointer to of the Password value passed in.
278+
func Password(v strfmt.Password) *strfmt.Password {
279+
return &v
280+
}
281+
282+
// PasswordValue returns the value of the Password pointer passed in or
283+
// the default value if the pointer is nil.
284+
func PasswordValue(v *strfmt.Password) strfmt.Password {
285+
if v == nil {
286+
return strfmt.Password("")
287+
}
288+
289+
return *v
290+
}

0 commit comments

Comments
 (0)