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