...

Source file src/github.com/go-openapi/strfmt/default.go

Documentation: github.com/go-openapi/strfmt

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

View as plain text