1// Copyright 2015 go-swagger maintainers
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//    http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package strfmt
16
17import (
18	"database/sql/driver"
19	"encoding/base64"
20	"encoding/json"
21	"errors"
22	"fmt"
23	"net/mail"
24	"regexp"
25	"strings"
26
27	"github.com/asaskevich/govalidator"
28	"go.mongodb.org/mongo-driver/bson"
29)
30
31const (
32	// HostnamePattern http://json-schema.org/latest/json-schema-validation.html#anchor114
33	//  A string instance is valid against this attribute if it is a valid
34	//  representation for an Internet host name, as defined by RFC 1034, section 3.1 [RFC1034].
35	//  http://tools.ietf.org/html/rfc1034#section-3.5
36	//  <digit> ::= any one of the ten digits 0 through 9
37	//  var digit = /[0-9]/;
38	//  <letter> ::= any one of the 52 alphabetic characters A through Z in upper case and a through z in lower case
39	//  var letter = /[a-zA-Z]/;
40	//  <let-dig> ::= <letter> | <digit>
41	//  var letDig = /[0-9a-zA-Z]/;
42	//  <let-dig-hyp> ::= <let-dig> | "-"
43	//  var letDigHyp = /[-0-9a-zA-Z]/;
44	//  <ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>
45	//  var ldhStr = /[-0-9a-zA-Z]+/;
46	//  <label> ::= <letter> [ [ <ldh-str> ] <let-dig> ]
47	//  var label = /[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?/;
48	//  <subdomain> ::= <label> | <subdomain> "." <label>
49	//  var subdomain = /^[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?(\.[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?)*$/;
50	//  <domain> ::= <subdomain> | " "
51	//
52	// Additional validations:
53	//   - for FDQNs, top-level domain (e.g. ".com"), is at least to letters long (no special characters here)
54	//   - hostnames may start with a digit [RFC1123]
55	//   - special registered names with an underscore ('_') are not allowed in this context
56	//   - dashes are permitted, but not at the start or the end of a segment
57	//   - long top-level domain names (e.g. example.london) are permitted
58	//   - symbol unicode points are permitted (e.g. emoji) (not for top-level domain)
59	HostnamePattern = `^([a-zA-Z0-9\p{S}\p{L}]((-?[a-zA-Z0-9\p{S}\p{L}]{0,62})?)|([a-zA-Z0-9\p{S}\p{L}](([a-zA-Z0-9-\p{S}\p{L}]{0,61}[a-zA-Z0-9\p{S}\p{L}])?)(\.)){1,}([a-zA-Z\p{L}]){2,63})$`
60	// UUIDPattern Regex for UUID that allows uppercase
61	UUIDPattern = `(?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}$`
62	// UUID3Pattern Regex for UUID3 that allows uppercase
63	UUID3Pattern = `(?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?3[0-9a-f]{3}-?[0-9a-f]{4}-?[0-9a-f]{12}$`
64	// UUID4Pattern Regex for UUID4 that allows uppercase
65	UUID4Pattern = `(?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?4[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12}$`
66	// UUID5Pattern Regex for UUID5 that allows uppercase
67	UUID5Pattern = `(?i)^[0-9a-f]{8}-?[0-9a-f]{4}-?5[0-9a-f]{3}-?[89ab][0-9a-f]{3}-?[0-9a-f]{12}$`
68	// json null type
69	jsonNull = "null"
70)
71
72var (
73	rxHostname = regexp.MustCompile(HostnamePattern)
74	rxUUID     = regexp.MustCompile(UUIDPattern)
75	rxUUID3    = regexp.MustCompile(UUID3Pattern)
76	rxUUID4    = regexp.MustCompile(UUID4Pattern)
77	rxUUID5    = regexp.MustCompile(UUID5Pattern)
78)
79
80// IsHostname returns true when the string is a valid hostname
81func IsHostname(str string) bool {
82	if !rxHostname.MatchString(str) {
83		return false
84	}
85
86	// the sum of all label octets and label lengths is limited to 255.
87	if len(str) > 255 {
88		return false
89	}
90
91	// Each node has a label, which is zero to 63 octets in length
92	parts := strings.Split(str, ".")
93	valid := true
94	for _, p := range parts {
95		if len(p) > 63 {
96			valid = false
97		}
98	}
99	return valid
100}
101
102// IsUUID returns true is the string matches a UUID, upper case is allowed
103func IsUUID(str string) bool {
104	return rxUUID.MatchString(str)
105}
106
107// IsUUID3 returns true is the string matches a UUID, upper case is allowed
108func IsUUID3(str string) bool {
109	return rxUUID3.MatchString(str)
110}
111
112// IsUUID4 returns true is the string matches a UUID, upper case is allowed
113func IsUUID4(str string) bool {
114	return rxUUID4.MatchString(str)
115}
116
117// IsUUID5 returns true is the string matches a UUID, upper case is allowed
118func IsUUID5(str string) bool {
119	return rxUUID5.MatchString(str)
120}
121
122// IsEmail validates an email address.
123func IsEmail(str string) bool {
124	addr, e := mail.ParseAddress(str)
125	return e == nil && addr.Address != ""
126}
127
128func init() {
129	// register formats in the default registry:
130	//   - byte
131	//   - creditcard
132	//   - email
133	//   - hexcolor
134	//   - hostname
135	//   - ipv4
136	//   - ipv6
137	//   - cidr
138	//   - isbn
139	//   - isbn10
140	//   - isbn13
141	//   - mac
142	//   - password
143	//   - rgbcolor
144	//   - ssn
145	//   - uri
146	//   - uuid
147	//   - uuid3
148	//   - uuid4
149	//   - uuid5
150	u := URI("")
151	Default.Add("uri", &u, govalidator.IsRequestURI)
152
153	eml := Email("")
154	Default.Add("email", &eml, IsEmail)
155
156	hn := Hostname("")
157	Default.Add("hostname", &hn, IsHostname)
158
159	ip4 := IPv4("")
160	Default.Add("ipv4", &ip4, govalidator.IsIPv4)
161
162	ip6 := IPv6("")
163	Default.Add("ipv6", &ip6, govalidator.IsIPv6)
164
165	cidr := CIDR("")
166	Default.Add("cidr", &cidr, govalidator.IsCIDR)
167
168	mac := MAC("")
169	Default.Add("mac", &mac, govalidator.IsMAC)
170
171	uid := UUID("")
172	Default.Add("uuid", &uid, IsUUID)
173
174	uid3 := UUID3("")
175	Default.Add("uuid3", &uid3, IsUUID3)
176
177	uid4 := UUID4("")
178	Default.Add("uuid4", &uid4, IsUUID4)
179
180	uid5 := UUID5("")
181	Default.Add("uuid5", &uid5, IsUUID5)
182
183	isbn := ISBN("")
184	Default.Add("isbn", &isbn, func(str string) bool { return govalidator.IsISBN10(str) || govalidator.IsISBN13(str) })
185
186	isbn10 := ISBN10("")
187	Default.Add("isbn10", &isbn10, govalidator.IsISBN10)
188
189	isbn13 := ISBN13("")
190	Default.Add("isbn13", &isbn13, govalidator.IsISBN13)
191
192	cc := CreditCard("")
193	Default.Add("creditcard", &cc, govalidator.IsCreditCard)
194
195	ssn := SSN("")
196	Default.Add("ssn", &ssn, govalidator.IsSSN)
197
198	hc := HexColor("")
199	Default.Add("hexcolor", &hc, govalidator.IsHexcolor)
200
201	rc := RGBColor("")
202	Default.Add("rgbcolor", &rc, govalidator.IsRGBcolor)
203
204	b64 := Base64([]byte(nil))
205	Default.Add("byte", &b64, govalidator.IsBase64)
206
207	pw := Password("")
208	Default.Add("password", &pw, func(_ string) bool { return true })
209}
210
211// Base64 represents a base64 encoded string, using URLEncoding alphabet
212//
213// swagger:strfmt byte
214type Base64 []byte
215
216// MarshalText turns this instance into text
217func (b Base64) MarshalText() ([]byte, error) {
218	enc := base64.URLEncoding
219	src := []byte(b)
220	buf := make([]byte, enc.EncodedLen(len(src)))
221	enc.Encode(buf, src)
222	return buf, nil
223}
224
225// UnmarshalText hydrates this instance from text
226func (b *Base64) UnmarshalText(data []byte) error { // validation is performed later on
227	enc := base64.URLEncoding
228	dbuf := make([]byte, enc.DecodedLen(len(data)))
229
230	n, err := enc.Decode(dbuf, data)
231	if err != nil {
232		return err
233	}
234
235	*b = dbuf[:n]
236	return nil
237}
238
239// Scan read a value from a database driver
240func (b *Base64) Scan(raw interface{}) error {
241	switch v := raw.(type) {
242	case []byte:
243		dbuf := make([]byte, base64.StdEncoding.DecodedLen(len(v)))
244		n, err := base64.StdEncoding.Decode(dbuf, v)
245		if err != nil {
246			return err
247		}
248		*b = dbuf[:n]
249	case string:
250		vv, err := base64.StdEncoding.DecodeString(v)
251		if err != nil {
252			return err
253		}
254		*b = Base64(vv)
255	default:
256		return fmt.Errorf("cannot sql.Scan() strfmt.Base64 from: %#v", v)
257	}
258
259	return nil
260}
261
262// Value converts a value to a database driver value
263func (b Base64) Value() (driver.Value, error) {
264	return driver.Value(b.String()), nil
265}
266
267func (b Base64) String() string {
268	return base64.StdEncoding.EncodeToString([]byte(b))
269}
270
271// MarshalJSON returns the Base64 as JSON
272func (b Base64) MarshalJSON() ([]byte, error) {
273	return json.Marshal(b.String())
274}
275
276// UnmarshalJSON sets the Base64 from JSON
277func (b *Base64) UnmarshalJSON(data []byte) error {
278	var b64str string
279	if err := json.Unmarshal(data, &b64str); err != nil {
280		return err
281	}
282	vb, err := base64.StdEncoding.DecodeString(b64str)
283	if err != nil {
284		return err
285	}
286	*b = Base64(vb)
287	return nil
288}
289
290// MarshalBSON document from this value
291func (b Base64) MarshalBSON() ([]byte, error) {
292	return bson.Marshal(bson.M{"data": b.String()})
293}
294
295// UnmarshalBSON document into this value
296func (b *Base64) UnmarshalBSON(data []byte) error {
297	var m bson.M
298	if err := bson.Unmarshal(data, &m); err != nil {
299		return err
300	}
301
302	if bd, ok := m["data"].(string); ok {
303		vb, err := base64.StdEncoding.DecodeString(bd)
304		if err != nil {
305			return err
306		}
307		*b = Base64(vb)
308		return nil
309	}
310	return errors.New("couldn't unmarshal bson bytes as base64")
311}
312
313// DeepCopyInto copies the receiver and writes its value into out.
314func (b *Base64) DeepCopyInto(out *Base64) {
315	*out = *b
316}
317
318// DeepCopy copies the receiver into a new Base64.
319func (b *Base64) DeepCopy() *Base64 {
320	if b == nil {
321		return nil
322	}
323	out := new(Base64)
324	b.DeepCopyInto(out)
325	return out
326}
327
328// URI represents the uri string format as specified by the json schema spec
329//
330// swagger:strfmt uri
331type URI string
332
333// MarshalText turns this instance into text
334func (u URI) MarshalText() ([]byte, error) {
335	return []byte(string(u)), nil
336}
337
338// UnmarshalText hydrates this instance from text
339func (u *URI) UnmarshalText(data []byte) error { // validation is performed later on
340	*u = URI(string(data))
341	return nil
342}
343
344// Scan read a value from a database driver
345func (u *URI) Scan(raw interface{}) error {
346	switch v := raw.(type) {
347	case []byte:
348		*u = URI(string(v))
349	case string:
350		*u = URI(v)
351	default:
352		return fmt.Errorf("cannot sql.Scan() strfmt.URI from: %#v", v)
353	}
354
355	return nil
356}
357
358// Value converts a value to a database driver value
359func (u URI) Value() (driver.Value, error) {
360	return driver.Value(string(u)), nil
361}
362
363func (u URI) String() string {
364	return string(u)
365}
366
367// MarshalJSON returns the URI as JSON
368func (u URI) MarshalJSON() ([]byte, error) {
369	return json.Marshal(string(u))
370}
371
372// UnmarshalJSON sets the URI from JSON
373func (u *URI) UnmarshalJSON(data []byte) error {
374	var uristr string
375	if err := json.Unmarshal(data, &uristr); err != nil {
376		return err
377	}
378	*u = URI(uristr)
379	return nil
380}
381
382// MarshalBSON document from this value
383func (u URI) MarshalBSON() ([]byte, error) {
384	return bson.Marshal(bson.M{"data": u.String()})
385}
386
387// UnmarshalBSON document into this value
388func (u *URI) UnmarshalBSON(data []byte) error {
389	var m bson.M
390	if err := bson.Unmarshal(data, &m); err != nil {
391		return err
392	}
393
394	if ud, ok := m["data"].(string); ok {
395		*u = URI(ud)
396		return nil
397	}
398	return errors.New("couldn't unmarshal bson bytes as uri")
399}
400
401// DeepCopyInto copies the receiver and writes its value into out.
402func (u *URI) DeepCopyInto(out *URI) {
403	*out = *u
404}
405
406// DeepCopy copies the receiver into a new URI.
407func (u *URI) DeepCopy() *URI {
408	if u == nil {
409		return nil
410	}
411	out := new(URI)
412	u.DeepCopyInto(out)
413	return out
414}
415
416// Email represents the email string format as specified by the json schema spec
417//
418// swagger:strfmt email
419type Email string
420
421// MarshalText turns this instance into text
422func (e Email) MarshalText() ([]byte, error) {
423	return []byte(string(e)), nil
424}
425
426// UnmarshalText hydrates this instance from text
427func (e *Email) UnmarshalText(data []byte) error { // validation is performed later on
428	*e = Email(string(data))
429	return nil
430}
431
432// Scan read a value from a database driver
433func (e *Email) Scan(raw interface{}) error {
434	switch v := raw.(type) {
435	case []byte:
436		*e = Email(string(v))
437	case string:
438		*e = Email(v)
439	default:
440		return fmt.Errorf("cannot sql.Scan() strfmt.Email from: %#v", v)
441	}
442
443	return nil
444}
445
446// Value converts a value to a database driver value
447func (e Email) Value() (driver.Value, error) {
448	return driver.Value(string(e)), nil
449}
450
451func (e Email) String() string {
452	return string(e)
453}
454
455// MarshalJSON returns the Email as JSON
456func (e Email) MarshalJSON() ([]byte, error) {
457	return json.Marshal(string(e))
458}
459
460// UnmarshalJSON sets the Email from JSON
461func (e *Email) UnmarshalJSON(data []byte) error {
462	var estr string
463	if err := json.Unmarshal(data, &estr); err != nil {
464		return err
465	}
466	*e = Email(estr)
467	return nil
468}
469
470// MarshalBSON document from this value
471func (e Email) MarshalBSON() ([]byte, error) {
472	return bson.Marshal(bson.M{"data": e.String()})
473}
474
475// UnmarshalBSON document into this value
476func (e *Email) UnmarshalBSON(data []byte) error {
477	var m bson.M
478	if err := bson.Unmarshal(data, &m); err != nil {
479		return err
480	}
481
482	if ud, ok := m["data"].(string); ok {
483		*e = Email(ud)
484		return nil
485	}
486	return errors.New("couldn't unmarshal bson bytes as email")
487}
488
489// DeepCopyInto copies the receiver and writes its value into out.
490func (e *Email) DeepCopyInto(out *Email) {
491	*out = *e
492}
493
494// DeepCopy copies the receiver into a new Email.
495func (e *Email) DeepCopy() *Email {
496	if e == nil {
497		return nil
498	}
499	out := new(Email)
500	e.DeepCopyInto(out)
501	return out
502}
503
504// Hostname represents the hostname string format as specified by the json schema spec
505//
506// swagger:strfmt hostname
507type Hostname string
508
509// MarshalText turns this instance into text
510func (h Hostname) MarshalText() ([]byte, error) {
511	return []byte(string(h)), nil
512}
513
514// UnmarshalText hydrates this instance from text
515func (h *Hostname) UnmarshalText(data []byte) error { // validation is performed later on
516	*h = Hostname(string(data))
517	return nil
518}
519
520// Scan read a value from a database driver
521func (h *Hostname) Scan(raw interface{}) error {
522	switch v := raw.(type) {
523	case []byte:
524		*h = Hostname(string(v))
525	case string:
526		*h = Hostname(v)
527	default:
528		return fmt.Errorf("cannot sql.Scan() strfmt.Hostname from: %#v", v)
529	}
530
531	return nil
532}
533
534// Value converts a value to a database driver value
535func (h Hostname) Value() (driver.Value, error) {
536	return driver.Value(string(h)), nil
537}
538
539func (h Hostname) String() string {
540	return string(h)
541}
542
543// MarshalJSON returns the Hostname as JSON
544func (h Hostname) MarshalJSON() ([]byte, error) {
545	return json.Marshal(string(h))
546}
547
548// UnmarshalJSON sets the Hostname from JSON
549func (h *Hostname) UnmarshalJSON(data []byte) error {
550	var hstr string
551	if err := json.Unmarshal(data, &hstr); err != nil {
552		return err
553	}
554	*h = Hostname(hstr)
555	return nil
556}
557
558// MarshalBSON document from this value
559func (h Hostname) MarshalBSON() ([]byte, error) {
560	return bson.Marshal(bson.M{"data": h.String()})
561}
562
563// UnmarshalBSON document into this value
564func (h *Hostname) UnmarshalBSON(data []byte) error {
565	var m bson.M
566	if err := bson.Unmarshal(data, &m); err != nil {
567		return err
568	}
569
570	if ud, ok := m["data"].(string); ok {
571		*h = Hostname(ud)
572		return nil
573	}
574	return errors.New("couldn't unmarshal bson bytes as hostname")
575}
576
577// DeepCopyInto copies the receiver and writes its value into out.
578func (h *Hostname) DeepCopyInto(out *Hostname) {
579	*out = *h
580}
581
582// DeepCopy copies the receiver into a new Hostname.
583func (h *Hostname) DeepCopy() *Hostname {
584	if h == nil {
585		return nil
586	}
587	out := new(Hostname)
588	h.DeepCopyInto(out)
589	return out
590}
591
592// IPv4 represents an IP v4 address
593//
594// swagger:strfmt ipv4
595type IPv4 string
596
597// MarshalText turns this instance into text
598func (u IPv4) MarshalText() ([]byte, error) {
599	return []byte(string(u)), nil
600}
601
602// UnmarshalText hydrates this instance from text
603func (u *IPv4) UnmarshalText(data []byte) error { // validation is performed later on
604	*u = IPv4(string(data))
605	return nil
606}
607
608// Scan read a value from a database driver
609func (u *IPv4) Scan(raw interface{}) error {
610	switch v := raw.(type) {
611	case []byte:
612		*u = IPv4(string(v))
613	case string:
614		*u = IPv4(v)
615	default:
616		return fmt.Errorf("cannot sql.Scan() strfmt.IPv4 from: %#v", v)
617	}
618
619	return nil
620}
621
622// Value converts a value to a database driver value
623func (u IPv4) Value() (driver.Value, error) {
624	return driver.Value(string(u)), nil
625}
626
627func (u IPv4) String() string {
628	return string(u)
629}
630
631// MarshalJSON returns the IPv4 as JSON
632func (u IPv4) MarshalJSON() ([]byte, error) {
633	return json.Marshal(string(u))
634}
635
636// UnmarshalJSON sets the IPv4 from JSON
637func (u *IPv4) UnmarshalJSON(data []byte) error {
638	var ustr string
639	if err := json.Unmarshal(data, &ustr); err != nil {
640		return err
641	}
642	*u = IPv4(ustr)
643	return nil
644}
645
646// MarshalBSON document from this value
647func (u IPv4) MarshalBSON() ([]byte, error) {
648	return bson.Marshal(bson.M{"data": u.String()})
649}
650
651// UnmarshalBSON document into this value
652func (u *IPv4) UnmarshalBSON(data []byte) error {
653	var m bson.M
654	if err := bson.Unmarshal(data, &m); err != nil {
655		return err
656	}
657
658	if ud, ok := m["data"].(string); ok {
659		*u = IPv4(ud)
660		return nil
661	}
662	return errors.New("couldn't unmarshal bson bytes as ipv4")
663}
664
665// DeepCopyInto copies the receiver and writes its value into out.
666func (u *IPv4) DeepCopyInto(out *IPv4) {
667	*out = *u
668}
669
670// DeepCopy copies the receiver into a new IPv4.
671func (u *IPv4) DeepCopy() *IPv4 {
672	if u == nil {
673		return nil
674	}
675	out := new(IPv4)
676	u.DeepCopyInto(out)
677	return out
678}
679
680// IPv6 represents an IP v6 address
681//
682// swagger:strfmt ipv6
683type IPv6 string
684
685// MarshalText turns this instance into text
686func (u IPv6) MarshalText() ([]byte, error) {
687	return []byte(string(u)), nil
688}
689
690// UnmarshalText hydrates this instance from text
691func (u *IPv6) UnmarshalText(data []byte) error { // validation is performed later on
692	*u = IPv6(string(data))
693	return nil
694}
695
696// Scan read a value from a database driver
697func (u *IPv6) Scan(raw interface{}) error {
698	switch v := raw.(type) {
699	case []byte:
700		*u = IPv6(string(v))
701	case string:
702		*u = IPv6(v)
703	default:
704		return fmt.Errorf("cannot sql.Scan() strfmt.IPv6 from: %#v", v)
705	}
706
707	return nil
708}
709
710// Value converts a value to a database driver value
711func (u IPv6) Value() (driver.Value, error) {
712	return driver.Value(string(u)), nil
713}
714
715func (u IPv6) String() string {
716	return string(u)
717}
718
719// MarshalJSON returns the IPv6 as JSON
720func (u IPv6) MarshalJSON() ([]byte, error) {
721	return json.Marshal(string(u))
722}
723
724// UnmarshalJSON sets the IPv6 from JSON
725func (u *IPv6) UnmarshalJSON(data []byte) error {
726	var ustr string
727	if err := json.Unmarshal(data, &ustr); err != nil {
728		return err
729	}
730	*u = IPv6(ustr)
731	return nil
732}
733
734// MarshalBSON document from this value
735func (u IPv6) MarshalBSON() ([]byte, error) {
736	return bson.Marshal(bson.M{"data": u.String()})
737}
738
739// UnmarshalBSON document into this value
740func (u *IPv6) UnmarshalBSON(data []byte) error {
741	var m bson.M
742	if err := bson.Unmarshal(data, &m); err != nil {
743		return err
744	}
745
746	if ud, ok := m["data"].(string); ok {
747		*u = IPv6(ud)
748		return nil
749	}
750	return errors.New("couldn't unmarshal bson bytes as ipv6")
751}
752
753// DeepCopyInto copies the receiver and writes its value into out.
754func (u *IPv6) DeepCopyInto(out *IPv6) {
755	*out = *u
756}
757
758// DeepCopy copies the receiver into a new IPv6.
759func (u *IPv6) DeepCopy() *IPv6 {
760	if u == nil {
761		return nil
762	}
763	out := new(IPv6)
764	u.DeepCopyInto(out)
765	return out
766}
767
768// CIDR represents a Classless Inter-Domain Routing notation
769//
770// swagger:strfmt cidr
771type CIDR string
772
773// MarshalText turns this instance into text
774func (u CIDR) MarshalText() ([]byte, error) {
775	return []byte(string(u)), nil
776}
777
778// UnmarshalText hydrates this instance from text
779func (u *CIDR) UnmarshalText(data []byte) error { // validation is performed later on
780	*u = CIDR(string(data))
781	return nil
782}
783
784// Scan read a value from a database driver
785func (u *CIDR) Scan(raw interface{}) error {
786	switch v := raw.(type) {
787	case []byte:
788		*u = CIDR(string(v))
789	case string:
790		*u = CIDR(v)
791	default:
792		return fmt.Errorf("cannot sql.Scan() strfmt.CIDR from: %#v", v)
793	}
794
795	return nil
796}
797
798// Value converts a value to a database driver value
799func (u CIDR) Value() (driver.Value, error) {
800	return driver.Value(string(u)), nil
801}
802
803func (u CIDR) String() string {
804	return string(u)
805}
806
807// MarshalJSON returns the CIDR as JSON
808func (u CIDR) MarshalJSON() ([]byte, error) {
809	return json.Marshal(string(u))
810}
811
812// UnmarshalJSON sets the CIDR from JSON
813func (u *CIDR) UnmarshalJSON(data []byte) error {
814	var ustr string
815	if err := json.Unmarshal(data, &ustr); err != nil {
816		return err
817	}
818	*u = CIDR(ustr)
819	return nil
820}
821
822// MarshalBSON document from this value
823func (u CIDR) MarshalBSON() ([]byte, error) {
824	return bson.Marshal(bson.M{"data": u.String()})
825}
826
827// UnmarshalBSON document into this value
828func (u *CIDR) UnmarshalBSON(data []byte) error {
829	var m bson.M
830	if err := bson.Unmarshal(data, &m); err != nil {
831		return err
832	}
833
834	if ud, ok := m["data"].(string); ok {
835		*u = CIDR(ud)
836		return nil
837	}
838	return errors.New("couldn't unmarshal bson bytes as CIDR")
839}
840
841// DeepCopyInto copies the receiver and writes its value into out.
842func (u *CIDR) DeepCopyInto(out *CIDR) {
843	*out = *u
844}
845
846// DeepCopy copies the receiver into a new CIDR.
847func (u *CIDR) DeepCopy() *CIDR {
848	if u == nil {
849		return nil
850	}
851	out := new(CIDR)
852	u.DeepCopyInto(out)
853	return out
854}
855
856// MAC represents a 48 bit MAC address
857//
858// swagger:strfmt mac
859type MAC string
860
861// MarshalText turns this instance into text
862func (u MAC) MarshalText() ([]byte, error) {
863	return []byte(string(u)), nil
864}
865
866// UnmarshalText hydrates this instance from text
867func (u *MAC) UnmarshalText(data []byte) error { // validation is performed later on
868	*u = MAC(string(data))
869	return nil
870}
871
872// Scan read a value from a database driver
873func (u *MAC) Scan(raw interface{}) error {
874	switch v := raw.(type) {
875	case []byte:
876		*u = MAC(string(v))
877	case string:
878		*u = MAC(v)
879	default:
880		return fmt.Errorf("cannot sql.Scan() strfmt.IPv4 from: %#v", v)
881	}
882
883	return nil
884}
885
886// Value converts a value to a database driver value
887func (u MAC) Value() (driver.Value, error) {
888	return driver.Value(string(u)), nil
889}
890
891func (u MAC) String() string {
892	return string(u)
893}
894
895// MarshalJSON returns the MAC as JSON
896func (u MAC) MarshalJSON() ([]byte, error) {
897	return json.Marshal(string(u))
898}
899
900// UnmarshalJSON sets the MAC from JSON
901func (u *MAC) UnmarshalJSON(data []byte) error {
902	var ustr string
903	if err := json.Unmarshal(data, &ustr); err != nil {
904		return err
905	}
906	*u = MAC(ustr)
907	return nil
908}
909
910// MarshalBSON document from this value
911func (u MAC) MarshalBSON() ([]byte, error) {
912	return bson.Marshal(bson.M{"data": u.String()})
913}
914
915// UnmarshalBSON document into this value
916func (u *MAC) UnmarshalBSON(data []byte) error {
917	var m bson.M
918	if err := bson.Unmarshal(data, &m); err != nil {
919		return err
920	}
921
922	if ud, ok := m["data"].(string); ok {
923		*u = MAC(ud)
924		return nil
925	}
926	return errors.New("couldn't unmarshal bson bytes as MAC")
927}
928
929// DeepCopyInto copies the receiver and writes its value into out.
930func (u *MAC) DeepCopyInto(out *MAC) {
931	*out = *u
932}
933
934// DeepCopy copies the receiver into a new MAC.
935func (u *MAC) DeepCopy() *MAC {
936	if u == nil {
937		return nil
938	}
939	out := new(MAC)
940	u.DeepCopyInto(out)
941	return out
942}
943
944// UUID represents a uuid string format
945//
946// swagger:strfmt uuid
947type UUID string
948
949// MarshalText turns this instance into text
950func (u UUID) MarshalText() ([]byte, error) {
951	return []byte(string(u)), nil
952}
953
954// UnmarshalText hydrates this instance from text
955func (u *UUID) UnmarshalText(data []byte) error { // validation is performed later on
956	*u = UUID(string(data))
957	return nil
958}
959
960// Scan read a value from a database driver
961func (u *UUID) Scan(raw interface{}) error {
962	switch v := raw.(type) {
963	case []byte:
964		*u = UUID(string(v))
965	case string:
966		*u = UUID(v)
967	default:
968		return fmt.Errorf("cannot sql.Scan() strfmt.UUID from: %#v", v)
969	}
970
971	return nil
972}
973
974// Value converts a value to a database driver value
975func (u UUID) Value() (driver.Value, error) {
976	return driver.Value(string(u)), nil
977}
978
979func (u UUID) String() string {
980	return string(u)
981}
982
983// MarshalJSON returns the UUID as JSON
984func (u UUID) MarshalJSON() ([]byte, error) {
985	return json.Marshal(string(u))
986}
987
988// UnmarshalJSON sets the UUID from JSON
989func (u *UUID) UnmarshalJSON(data []byte) error {
990	if string(data) == jsonNull {
991		return nil
992	}
993	var ustr string
994	if err := json.Unmarshal(data, &ustr); err != nil {
995		return err
996	}
997	*u = UUID(ustr)
998	return nil
999}
1000
1001// MarshalBSON document from this value
1002func (u UUID) MarshalBSON() ([]byte, error) {
1003	return bson.Marshal(bson.M{"data": u.String()})
1004}
1005
1006// UnmarshalBSON document into this value
1007func (u *UUID) UnmarshalBSON(data []byte) error {
1008	var m bson.M
1009	if err := bson.Unmarshal(data, &m); err != nil {
1010		return err
1011	}
1012
1013	if ud, ok := m["data"].(string); ok {
1014		*u = UUID(ud)
1015		return nil
1016	}
1017	return errors.New("couldn't unmarshal bson bytes as UUID")
1018}
1019
1020// DeepCopyInto copies the receiver and writes its value into out.
1021func (u *UUID) DeepCopyInto(out *UUID) {
1022	*out = *u
1023}
1024
1025// DeepCopy copies the receiver into a new UUID.
1026func (u *UUID) DeepCopy() *UUID {
1027	if u == nil {
1028		return nil
1029	}
1030	out := new(UUID)
1031	u.DeepCopyInto(out)
1032	return out
1033}
1034
1035// UUID3 represents a uuid3 string format
1036//
1037// swagger:strfmt uuid3
1038type UUID3 string
1039
1040// MarshalText turns this instance into text
1041func (u UUID3) MarshalText() ([]byte, error) {
1042	return []byte(string(u)), nil
1043}
1044
1045// UnmarshalText hydrates this instance from text
1046func (u *UUID3) UnmarshalText(data []byte) error { // validation is performed later on
1047	*u = UUID3(string(data))
1048	return nil
1049}
1050
1051// Scan read a value from a database driver
1052func (u *UUID3) Scan(raw interface{}) error {
1053	switch v := raw.(type) {
1054	case []byte:
1055		*u = UUID3(string(v))
1056	case string:
1057		*u = UUID3(v)
1058	default:
1059		return fmt.Errorf("cannot sql.Scan() strfmt.UUID3 from: %#v", v)
1060	}
1061
1062	return nil
1063}
1064
1065// Value converts a value to a database driver value
1066func (u UUID3) Value() (driver.Value, error) {
1067	return driver.Value(string(u)), nil
1068}
1069
1070func (u UUID3) String() string {
1071	return string(u)
1072}
1073
1074// MarshalJSON returns the UUID as JSON
1075func (u UUID3) MarshalJSON() ([]byte, error) {
1076	return json.Marshal(string(u))
1077}
1078
1079// UnmarshalJSON sets the UUID from JSON
1080func (u *UUID3) UnmarshalJSON(data []byte) error {
1081	if string(data) == jsonNull {
1082		return nil
1083	}
1084	var ustr string
1085	if err := json.Unmarshal(data, &ustr); err != nil {
1086		return err
1087	}
1088	*u = UUID3(ustr)
1089	return nil
1090}
1091
1092// MarshalBSON document from this value
1093func (u UUID3) MarshalBSON() ([]byte, error) {
1094	return bson.Marshal(bson.M{"data": u.String()})
1095}
1096
1097// UnmarshalBSON document into this value
1098func (u *UUID3) UnmarshalBSON(data []byte) error {
1099	var m bson.M
1100	if err := bson.Unmarshal(data, &m); err != nil {
1101		return err
1102	}
1103
1104	if ud, ok := m["data"].(string); ok {
1105		*u = UUID3(ud)
1106		return nil
1107	}
1108	return errors.New("couldn't unmarshal bson bytes as UUID3")
1109}
1110
1111// DeepCopyInto copies the receiver and writes its value into out.
1112func (u *UUID3) DeepCopyInto(out *UUID3) {
1113	*out = *u
1114}
1115
1116// DeepCopy copies the receiver into a new UUID3.
1117func (u *UUID3) DeepCopy() *UUID3 {
1118	if u == nil {
1119		return nil
1120	}
1121	out := new(UUID3)
1122	u.DeepCopyInto(out)
1123	return out
1124}
1125
1126// UUID4 represents a uuid4 string format
1127//
1128// swagger:strfmt uuid4
1129type UUID4 string
1130
1131// MarshalText turns this instance into text
1132func (u UUID4) MarshalText() ([]byte, error) {
1133	return []byte(string(u)), nil
1134}
1135
1136// UnmarshalText hydrates this instance from text
1137func (u *UUID4) UnmarshalText(data []byte) error { // validation is performed later on
1138	*u = UUID4(string(data))
1139	return nil
1140}
1141
1142// Scan read a value from a database driver
1143func (u *UUID4) Scan(raw interface{}) error {
1144	switch v := raw.(type) {
1145	case []byte:
1146		*u = UUID4(string(v))
1147	case string:
1148		*u = UUID4(v)
1149	default:
1150		return fmt.Errorf("cannot sql.Scan() strfmt.UUID4 from: %#v", v)
1151	}
1152
1153	return nil
1154}
1155
1156// Value converts a value to a database driver value
1157func (u UUID4) Value() (driver.Value, error) {
1158	return driver.Value(string(u)), nil
1159}
1160
1161func (u UUID4) String() string {
1162	return string(u)
1163}
1164
1165// MarshalJSON returns the UUID as JSON
1166func (u UUID4) MarshalJSON() ([]byte, error) {
1167	return json.Marshal(string(u))
1168}
1169
1170// UnmarshalJSON sets the UUID from JSON
1171func (u *UUID4) UnmarshalJSON(data []byte) error {
1172	if string(data) == jsonNull {
1173		return nil
1174	}
1175	var ustr string
1176	if err := json.Unmarshal(data, &ustr); err != nil {
1177		return err
1178	}
1179	*u = UUID4(ustr)
1180	return nil
1181}
1182
1183// MarshalBSON document from this value
1184func (u UUID4) MarshalBSON() ([]byte, error) {
1185	return bson.Marshal(bson.M{"data": u.String()})
1186}
1187
1188// UnmarshalBSON document into this value
1189func (u *UUID4) UnmarshalBSON(data []byte) error {
1190	var m bson.M
1191	if err := bson.Unmarshal(data, &m); err != nil {
1192		return err
1193	}
1194
1195	if ud, ok := m["data"].(string); ok {
1196		*u = UUID4(ud)
1197		return nil
1198	}
1199	return errors.New("couldn't unmarshal bson bytes as UUID4")
1200}
1201
1202// DeepCopyInto copies the receiver and writes its value into out.
1203func (u *UUID4) DeepCopyInto(out *UUID4) {
1204	*out = *u
1205}
1206
1207// DeepCopy copies the receiver into a new UUID4.
1208func (u *UUID4) DeepCopy() *UUID4 {
1209	if u == nil {
1210		return nil
1211	}
1212	out := new(UUID4)
1213	u.DeepCopyInto(out)
1214	return out
1215}
1216
1217// UUID5 represents a uuid5 string format
1218//
1219// swagger:strfmt uuid5
1220type UUID5 string
1221
1222// MarshalText turns this instance into text
1223func (u UUID5) MarshalText() ([]byte, error) {
1224	return []byte(string(u)), nil
1225}
1226
1227// UnmarshalText hydrates this instance from text
1228func (u *UUID5) UnmarshalText(data []byte) error { // validation is performed later on
1229	*u = UUID5(string(data))
1230	return nil
1231}
1232
1233// Scan read a value from a database driver
1234func (u *UUID5) Scan(raw interface{}) error {
1235	switch v := raw.(type) {
1236	case []byte:
1237		*u = UUID5(string(v))
1238	case string:
1239		*u = UUID5(v)
1240	default:
1241		return fmt.Errorf("cannot sql.Scan() strfmt.UUID5 from: %#v", v)
1242	}
1243
1244	return nil
1245}
1246
1247// Value converts a value to a database driver value
1248func (u UUID5) Value() (driver.Value, error) {
1249	return driver.Value(string(u)), nil
1250}
1251
1252func (u UUID5) String() string {
1253	return string(u)
1254}
1255
1256// MarshalJSON returns the UUID as JSON
1257func (u UUID5) MarshalJSON() ([]byte, error) {
1258	return json.Marshal(string(u))
1259}
1260
1261// UnmarshalJSON sets the UUID from JSON
1262func (u *UUID5) UnmarshalJSON(data []byte) error {
1263	if string(data) == jsonNull {
1264		return nil
1265	}
1266	var ustr string
1267	if err := json.Unmarshal(data, &ustr); err != nil {
1268		return err
1269	}
1270	*u = UUID5(ustr)
1271	return nil
1272}
1273
1274// MarshalBSON document from this value
1275func (u UUID5) MarshalBSON() ([]byte, error) {
1276	return bson.Marshal(bson.M{"data": u.String()})
1277}
1278
1279// UnmarshalBSON document into this value
1280func (u *UUID5) UnmarshalBSON(data []byte) error {
1281	var m bson.M
1282	if err := bson.Unmarshal(data, &m); err != nil {
1283		return err
1284	}
1285
1286	if ud, ok := m["data"].(string); ok {
1287		*u = UUID5(ud)
1288		return nil
1289	}
1290	return errors.New("couldn't unmarshal bson bytes as UUID5")
1291}
1292
1293// DeepCopyInto copies the receiver and writes its value into out.
1294func (u *UUID5) DeepCopyInto(out *UUID5) {
1295	*out = *u
1296}
1297
1298// DeepCopy copies the receiver into a new UUID5.
1299func (u *UUID5) DeepCopy() *UUID5 {
1300	if u == nil {
1301		return nil
1302	}
1303	out := new(UUID5)
1304	u.DeepCopyInto(out)
1305	return out
1306}
1307
1308// ISBN represents an isbn string format
1309//
1310// swagger:strfmt isbn
1311type ISBN string
1312
1313// MarshalText turns this instance into text
1314func (u ISBN) MarshalText() ([]byte, error) {
1315	return []byte(string(u)), nil
1316}
1317
1318// UnmarshalText hydrates this instance from text
1319func (u *ISBN) UnmarshalText(data []byte) error { // validation is performed later on
1320	*u = ISBN(string(data))
1321	return nil
1322}
1323
1324// Scan read a value from a database driver
1325func (u *ISBN) Scan(raw interface{}) error {
1326	switch v := raw.(type) {
1327	case []byte:
1328		*u = ISBN(string(v))
1329	case string:
1330		*u = ISBN(v)
1331	default:
1332		return fmt.Errorf("cannot sql.Scan() strfmt.ISBN from: %#v", v)
1333	}
1334
1335	return nil
1336}
1337
1338// Value converts a value to a database driver value
1339func (u ISBN) Value() (driver.Value, error) {
1340	return driver.Value(string(u)), nil
1341}
1342
1343func (u ISBN) String() string {
1344	return string(u)
1345}
1346
1347// MarshalJSON returns the ISBN as JSON
1348func (u ISBN) MarshalJSON() ([]byte, error) {
1349	return json.Marshal(string(u))
1350}
1351
1352// UnmarshalJSON sets the ISBN from JSON
1353func (u *ISBN) UnmarshalJSON(data []byte) error {
1354	if string(data) == jsonNull {
1355		return nil
1356	}
1357	var ustr string
1358	if err := json.Unmarshal(data, &ustr); err != nil {
1359		return err
1360	}
1361	*u = ISBN(ustr)
1362	return nil
1363}
1364
1365// MarshalBSON document from this value
1366func (u ISBN) MarshalBSON() ([]byte, error) {
1367	return bson.Marshal(bson.M{"data": u.String()})
1368}
1369
1370// UnmarshalBSON document into this value
1371func (u *ISBN) UnmarshalBSON(data []byte) error {
1372	var m bson.M
1373	if err := bson.Unmarshal(data, &m); err != nil {
1374		return err
1375	}
1376
1377	if ud, ok := m["data"].(string); ok {
1378		*u = ISBN(ud)
1379		return nil
1380	}
1381	return errors.New("couldn't unmarshal bson bytes as ISBN")
1382}
1383
1384// DeepCopyInto copies the receiver and writes its value into out.
1385func (u *ISBN) DeepCopyInto(out *ISBN) {
1386	*out = *u
1387}
1388
1389// DeepCopy copies the receiver into a new ISBN.
1390func (u *ISBN) DeepCopy() *ISBN {
1391	if u == nil {
1392		return nil
1393	}
1394	out := new(ISBN)
1395	u.DeepCopyInto(out)
1396	return out
1397}
1398
1399// ISBN10 represents an isbn 10 string format
1400//
1401// swagger:strfmt isbn10
1402type ISBN10 string
1403
1404// MarshalText turns this instance into text
1405func (u ISBN10) MarshalText() ([]byte, error) {
1406	return []byte(string(u)), nil
1407}
1408
1409// UnmarshalText hydrates this instance from text
1410func (u *ISBN10) UnmarshalText(data []byte) error { // validation is performed later on
1411	*u = ISBN10(string(data))
1412	return nil
1413}
1414
1415// Scan read a value from a database driver
1416func (u *ISBN10) Scan(raw interface{}) error {
1417	switch v := raw.(type) {
1418	case []byte:
1419		*u = ISBN10(string(v))
1420	case string:
1421		*u = ISBN10(v)
1422	default:
1423		return fmt.Errorf("cannot sql.Scan() strfmt.ISBN10 from: %#v", v)
1424	}
1425
1426	return nil
1427}
1428
1429// Value converts a value to a database driver value
1430func (u ISBN10) Value() (driver.Value, error) {
1431	return driver.Value(string(u)), nil
1432}
1433
1434func (u ISBN10) String() string {
1435	return string(u)
1436}
1437
1438// MarshalJSON returns the ISBN10 as JSON
1439func (u ISBN10) MarshalJSON() ([]byte, error) {
1440	return json.Marshal(string(u))
1441}
1442
1443// UnmarshalJSON sets the ISBN10 from JSON
1444func (u *ISBN10) UnmarshalJSON(data []byte) error {
1445	if string(data) == jsonNull {
1446		return nil
1447	}
1448	var ustr string
1449	if err := json.Unmarshal(data, &ustr); err != nil {
1450		return err
1451	}
1452	*u = ISBN10(ustr)
1453	return nil
1454}
1455
1456// MarshalBSON document from this value
1457func (u ISBN10) MarshalBSON() ([]byte, error) {
1458	return bson.Marshal(bson.M{"data": u.String()})
1459}
1460
1461// UnmarshalBSON document into this value
1462func (u *ISBN10) UnmarshalBSON(data []byte) error {
1463	var m bson.M
1464	if err := bson.Unmarshal(data, &m); err != nil {
1465		return err
1466	}
1467
1468	if ud, ok := m["data"].(string); ok {
1469		*u = ISBN10(ud)
1470		return nil
1471	}
1472	return errors.New("couldn't unmarshal bson bytes as ISBN10")
1473}
1474
1475// DeepCopyInto copies the receiver and writes its value into out.
1476func (u *ISBN10) DeepCopyInto(out *ISBN10) {
1477	*out = *u
1478}
1479
1480// DeepCopy copies the receiver into a new ISBN10.
1481func (u *ISBN10) DeepCopy() *ISBN10 {
1482	if u == nil {
1483		return nil
1484	}
1485	out := new(ISBN10)
1486	u.DeepCopyInto(out)
1487	return out
1488}
1489
1490// ISBN13 represents an isbn 13 string format
1491//
1492// swagger:strfmt isbn13
1493type ISBN13 string
1494
1495// MarshalText turns this instance into text
1496func (u ISBN13) MarshalText() ([]byte, error) {
1497	return []byte(string(u)), nil
1498}
1499
1500// UnmarshalText hydrates this instance from text
1501func (u *ISBN13) UnmarshalText(data []byte) error { // validation is performed later on
1502	*u = ISBN13(string(data))
1503	return nil
1504}
1505
1506// Scan read a value from a database driver
1507func (u *ISBN13) Scan(raw interface{}) error {
1508	switch v := raw.(type) {
1509	case []byte:
1510		*u = ISBN13(string(v))
1511	case string:
1512		*u = ISBN13(v)
1513	default:
1514		return fmt.Errorf("cannot sql.Scan() strfmt.ISBN13 from: %#v", v)
1515	}
1516
1517	return nil
1518}
1519
1520// Value converts a value to a database driver value
1521func (u ISBN13) Value() (driver.Value, error) {
1522	return driver.Value(string(u)), nil
1523}
1524
1525func (u ISBN13) String() string {
1526	return string(u)
1527}
1528
1529// MarshalJSON returns the ISBN13 as JSON
1530func (u ISBN13) MarshalJSON() ([]byte, error) {
1531	return json.Marshal(string(u))
1532}
1533
1534// UnmarshalJSON sets the ISBN13 from JSON
1535func (u *ISBN13) UnmarshalJSON(data []byte) error {
1536	if string(data) == jsonNull {
1537		return nil
1538	}
1539	var ustr string
1540	if err := json.Unmarshal(data, &ustr); err != nil {
1541		return err
1542	}
1543	*u = ISBN13(ustr)
1544	return nil
1545}
1546
1547// MarshalBSON document from this value
1548func (u ISBN13) MarshalBSON() ([]byte, error) {
1549	return bson.Marshal(bson.M{"data": u.String()})
1550}
1551
1552// UnmarshalBSON document into this value
1553func (u *ISBN13) UnmarshalBSON(data []byte) error {
1554	var m bson.M
1555	if err := bson.Unmarshal(data, &m); err != nil {
1556		return err
1557	}
1558
1559	if ud, ok := m["data"].(string); ok {
1560		*u = ISBN13(ud)
1561		return nil
1562	}
1563	return errors.New("couldn't unmarshal bson bytes as ISBN13")
1564}
1565
1566// DeepCopyInto copies the receiver and writes its value into out.
1567func (u *ISBN13) DeepCopyInto(out *ISBN13) {
1568	*out = *u
1569}
1570
1571// DeepCopy copies the receiver into a new ISBN13.
1572func (u *ISBN13) DeepCopy() *ISBN13 {
1573	if u == nil {
1574		return nil
1575	}
1576	out := new(ISBN13)
1577	u.DeepCopyInto(out)
1578	return out
1579}
1580
1581// CreditCard represents a credit card string format
1582//
1583// swagger:strfmt creditcard
1584type CreditCard string
1585
1586// MarshalText turns this instance into text
1587func (u CreditCard) MarshalText() ([]byte, error) {
1588	return []byte(string(u)), nil
1589}
1590
1591// UnmarshalText hydrates this instance from text
1592func (u *CreditCard) UnmarshalText(data []byte) error { // validation is performed later on
1593	*u = CreditCard(string(data))
1594	return nil
1595}
1596
1597// Scan read a value from a database driver
1598func (u *CreditCard) Scan(raw interface{}) error {
1599	switch v := raw.(type) {
1600	case []byte:
1601		*u = CreditCard(string(v))
1602	case string:
1603		*u = CreditCard(v)
1604	default:
1605		return fmt.Errorf("cannot sql.Scan() strfmt.CreditCard from: %#v", v)
1606	}
1607
1608	return nil
1609}
1610
1611// Value converts a value to a database driver value
1612func (u CreditCard) Value() (driver.Value, error) {
1613	return driver.Value(string(u)), nil
1614}
1615
1616func (u CreditCard) String() string {
1617	return string(u)
1618}
1619
1620// MarshalJSON returns the CreditCard as JSON
1621func (u CreditCard) MarshalJSON() ([]byte, error) {
1622	return json.Marshal(string(u))
1623}
1624
1625// UnmarshalJSON sets the CreditCard from JSON
1626func (u *CreditCard) UnmarshalJSON(data []byte) error {
1627	if string(data) == jsonNull {
1628		return nil
1629	}
1630	var ustr string
1631	if err := json.Unmarshal(data, &ustr); err != nil {
1632		return err
1633	}
1634	*u = CreditCard(ustr)
1635	return nil
1636}
1637
1638// MarshalBSON document from this value
1639func (u CreditCard) MarshalBSON() ([]byte, error) {
1640	return bson.Marshal(bson.M{"data": u.String()})
1641}
1642
1643// UnmarshalBSON document into this value
1644func (u *CreditCard) UnmarshalBSON(data []byte) error {
1645	var m bson.M
1646	if err := bson.Unmarshal(data, &m); err != nil {
1647		return err
1648	}
1649
1650	if ud, ok := m["data"].(string); ok {
1651		*u = CreditCard(ud)
1652		return nil
1653	}
1654	return errors.New("couldn't unmarshal bson bytes as CreditCard")
1655}
1656
1657// DeepCopyInto copies the receiver and writes its value into out.
1658func (u *CreditCard) DeepCopyInto(out *CreditCard) {
1659	*out = *u
1660}
1661
1662// DeepCopy copies the receiver into a new CreditCard.
1663func (u *CreditCard) DeepCopy() *CreditCard {
1664	if u == nil {
1665		return nil
1666	}
1667	out := new(CreditCard)
1668	u.DeepCopyInto(out)
1669	return out
1670}
1671
1672// SSN represents a social security string format
1673//
1674// swagger:strfmt ssn
1675type SSN string
1676
1677// MarshalText turns this instance into text
1678func (u SSN) MarshalText() ([]byte, error) {
1679	return []byte(string(u)), nil
1680}
1681
1682// UnmarshalText hydrates this instance from text
1683func (u *SSN) UnmarshalText(data []byte) error { // validation is performed later on
1684	*u = SSN(string(data))
1685	return nil
1686}
1687
1688// Scan read a value from a database driver
1689func (u *SSN) Scan(raw interface{}) error {
1690	switch v := raw.(type) {
1691	case []byte:
1692		*u = SSN(string(v))
1693	case string:
1694		*u = SSN(v)
1695	default:
1696		return fmt.Errorf("cannot sql.Scan() strfmt.SSN from: %#v", v)
1697	}
1698
1699	return nil
1700}
1701
1702// Value converts a value to a database driver value
1703func (u SSN) Value() (driver.Value, error) {
1704	return driver.Value(string(u)), nil
1705}
1706
1707func (u SSN) String() string {
1708	return string(u)
1709}
1710
1711// MarshalJSON returns the SSN as JSON
1712func (u SSN) MarshalJSON() ([]byte, error) {
1713	return json.Marshal(string(u))
1714}
1715
1716// UnmarshalJSON sets the SSN from JSON
1717func (u *SSN) UnmarshalJSON(data []byte) error {
1718	if string(data) == jsonNull {
1719		return nil
1720	}
1721	var ustr string
1722	if err := json.Unmarshal(data, &ustr); err != nil {
1723		return err
1724	}
1725	*u = SSN(ustr)
1726	return nil
1727}
1728
1729// MarshalBSON document from this value
1730func (u SSN) MarshalBSON() ([]byte, error) {
1731	return bson.Marshal(bson.M{"data": u.String()})
1732}
1733
1734// UnmarshalBSON document into this value
1735func (u *SSN) UnmarshalBSON(data []byte) error {
1736	var m bson.M
1737	if err := bson.Unmarshal(data, &m); err != nil {
1738		return err
1739	}
1740
1741	if ud, ok := m["data"].(string); ok {
1742		*u = SSN(ud)
1743		return nil
1744	}
1745	return errors.New("couldn't unmarshal bson bytes as SSN")
1746}
1747
1748// DeepCopyInto copies the receiver and writes its value into out.
1749func (u *SSN) DeepCopyInto(out *SSN) {
1750	*out = *u
1751}
1752
1753// DeepCopy copies the receiver into a new SSN.
1754func (u *SSN) DeepCopy() *SSN {
1755	if u == nil {
1756		return nil
1757	}
1758	out := new(SSN)
1759	u.DeepCopyInto(out)
1760	return out
1761}
1762
1763// HexColor represents a hex color string format
1764//
1765// swagger:strfmt hexcolor
1766type HexColor string
1767
1768// MarshalText turns this instance into text
1769func (h HexColor) MarshalText() ([]byte, error) {
1770	return []byte(string(h)), nil
1771}
1772
1773// UnmarshalText hydrates this instance from text
1774func (h *HexColor) UnmarshalText(data []byte) error { // validation is performed later on
1775	*h = HexColor(string(data))
1776	return nil
1777}
1778
1779// Scan read a value from a database driver
1780func (h *HexColor) Scan(raw interface{}) error {
1781	switch v := raw.(type) {
1782	case []byte:
1783		*h = HexColor(string(v))
1784	case string:
1785		*h = HexColor(v)
1786	default:
1787		return fmt.Errorf("cannot sql.Scan() strfmt.HexColor from: %#v", v)
1788	}
1789
1790	return nil
1791}
1792
1793// Value converts a value to a database driver value
1794func (h HexColor) Value() (driver.Value, error) {
1795	return driver.Value(string(h)), nil
1796}
1797
1798func (h HexColor) String() string {
1799	return string(h)
1800}
1801
1802// MarshalJSON returns the HexColor as JSON
1803func (h HexColor) MarshalJSON() ([]byte, error) {
1804	return json.Marshal(string(h))
1805}
1806
1807// UnmarshalJSON sets the HexColor from JSON
1808func (h *HexColor) UnmarshalJSON(data []byte) error {
1809	if string(data) == jsonNull {
1810		return nil
1811	}
1812	var ustr string
1813	if err := json.Unmarshal(data, &ustr); err != nil {
1814		return err
1815	}
1816	*h = HexColor(ustr)
1817	return nil
1818}
1819
1820// MarshalBSON document from this value
1821func (h HexColor) MarshalBSON() ([]byte, error) {
1822	return bson.Marshal(bson.M{"data": h.String()})
1823}
1824
1825// UnmarshalBSON document into this value
1826func (h *HexColor) UnmarshalBSON(data []byte) error {
1827	var m bson.M
1828	if err := bson.Unmarshal(data, &m); err != nil {
1829		return err
1830	}
1831
1832	if ud, ok := m["data"].(string); ok {
1833		*h = HexColor(ud)
1834		return nil
1835	}
1836	return errors.New("couldn't unmarshal bson bytes as HexColor")
1837}
1838
1839// DeepCopyInto copies the receiver and writes its value into out.
1840func (h *HexColor) DeepCopyInto(out *HexColor) {
1841	*out = *h
1842}
1843
1844// DeepCopy copies the receiver into a new HexColor.
1845func (h *HexColor) DeepCopy() *HexColor {
1846	if h == nil {
1847		return nil
1848	}
1849	out := new(HexColor)
1850	h.DeepCopyInto(out)
1851	return out
1852}
1853
1854// RGBColor represents a RGB color string format
1855//
1856// swagger:strfmt rgbcolor
1857type RGBColor string
1858
1859// MarshalText turns this instance into text
1860func (r RGBColor) MarshalText() ([]byte, error) {
1861	return []byte(string(r)), nil
1862}
1863
1864// UnmarshalText hydrates this instance from text
1865func (r *RGBColor) UnmarshalText(data []byte) error { // validation is performed later on
1866	*r = RGBColor(string(data))
1867	return nil
1868}
1869
1870// Scan read a value from a database driver
1871func (r *RGBColor) Scan(raw interface{}) error {
1872	switch v := raw.(type) {
1873	case []byte:
1874		*r = RGBColor(string(v))
1875	case string:
1876		*r = RGBColor(v)
1877	default:
1878		return fmt.Errorf("cannot sql.Scan() strfmt.RGBColor from: %#v", v)
1879	}
1880
1881	return nil
1882}
1883
1884// Value converts a value to a database driver value
1885func (r RGBColor) Value() (driver.Value, error) {
1886	return driver.Value(string(r)), nil
1887}
1888
1889func (r RGBColor) String() string {
1890	return string(r)
1891}
1892
1893// MarshalJSON returns the RGBColor as JSON
1894func (r RGBColor) MarshalJSON() ([]byte, error) {
1895	return json.Marshal(string(r))
1896}
1897
1898// UnmarshalJSON sets the RGBColor from JSON
1899func (r *RGBColor) UnmarshalJSON(data []byte) error {
1900	if string(data) == jsonNull {
1901		return nil
1902	}
1903	var ustr string
1904	if err := json.Unmarshal(data, &ustr); err != nil {
1905		return err
1906	}
1907	*r = RGBColor(ustr)
1908	return nil
1909}
1910
1911// MarshalBSON document from this value
1912func (r RGBColor) MarshalBSON() ([]byte, error) {
1913	return bson.Marshal(bson.M{"data": r.String()})
1914}
1915
1916// UnmarshalBSON document into this value
1917func (r *RGBColor) UnmarshalBSON(data []byte) error {
1918	var m bson.M
1919	if err := bson.Unmarshal(data, &m); err != nil {
1920		return err
1921	}
1922
1923	if ud, ok := m["data"].(string); ok {
1924		*r = RGBColor(ud)
1925		return nil
1926	}
1927	return errors.New("couldn't unmarshal bson bytes as RGBColor")
1928}
1929
1930// DeepCopyInto copies the receiver and writes its value into out.
1931func (r *RGBColor) DeepCopyInto(out *RGBColor) {
1932	*out = *r
1933}
1934
1935// DeepCopy copies the receiver into a new RGBColor.
1936func (r *RGBColor) DeepCopy() *RGBColor {
1937	if r == nil {
1938		return nil
1939	}
1940	out := new(RGBColor)
1941	r.DeepCopyInto(out)
1942	return out
1943}
1944
1945// Password represents a password.
1946// This has no validations and is mainly used as a marker for UI components.
1947//
1948// swagger:strfmt password
1949type Password string
1950
1951// MarshalText turns this instance into text
1952func (r Password) MarshalText() ([]byte, error) {
1953	return []byte(string(r)), nil
1954}
1955
1956// UnmarshalText hydrates this instance from text
1957func (r *Password) UnmarshalText(data []byte) error { // validation is performed later on
1958	*r = Password(string(data))
1959	return nil
1960}
1961
1962// Scan read a value from a database driver
1963func (r *Password) Scan(raw interface{}) error {
1964	switch v := raw.(type) {
1965	case []byte:
1966		*r = Password(string(v))
1967	case string:
1968		*r = Password(v)
1969	default:
1970		return fmt.Errorf("cannot sql.Scan() strfmt.Password from: %#v", v)
1971	}
1972
1973	return nil
1974}
1975
1976// Value converts a value to a database driver value
1977func (r Password) Value() (driver.Value, error) {
1978	return driver.Value(string(r)), nil
1979}
1980
1981func (r Password) String() string {
1982	return string(r)
1983}
1984
1985// MarshalJSON returns the Password as JSON
1986func (r Password) MarshalJSON() ([]byte, error) {
1987	return json.Marshal(string(r))
1988}
1989
1990// UnmarshalJSON sets the Password from JSON
1991func (r *Password) UnmarshalJSON(data []byte) error {
1992	if string(data) == jsonNull {
1993		return nil
1994	}
1995	var ustr string
1996	if err := json.Unmarshal(data, &ustr); err != nil {
1997		return err
1998	}
1999	*r = Password(ustr)
2000	return nil
2001}
2002
2003// MarshalBSON document from this value
2004func (r Password) MarshalBSON() ([]byte, error) {
2005	return bson.Marshal(bson.M{"data": r.String()})
2006}
2007
2008// UnmarshalBSON document into this value
2009func (r *Password) UnmarshalBSON(data []byte) error {
2010	var m bson.M
2011	if err := bson.Unmarshal(data, &m); err != nil {
2012		return err
2013	}
2014
2015	if ud, ok := m["data"].(string); ok {
2016		*r = Password(ud)
2017		return nil
2018	}
2019	return errors.New("couldn't unmarshal bson bytes as Password")
2020}
2021
2022// DeepCopyInto copies the receiver and writes its value into out.
2023func (r *Password) DeepCopyInto(out *Password) {
2024	*out = *r
2025}
2026
2027// DeepCopy copies the receiver into a new Password.
2028func (r *Password) DeepCopy() *Password {
2029	if r == nil {
2030		return nil
2031	}
2032	out := new(Password)
2033	r.DeepCopyInto(out)
2034	return out
2035}
2036