PageRenderTime 5959ms CodeModel.GetById 136ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/github.com/go-openapi/strfmt/default.go

https://gitlab.com/unofficial-mirrors/kubernetes
Go | 1359 lines | 935 code | 246 blank | 178 comment | 48 complexity | c887116448d8e755d372b40beafe427b MD5 | raw file
  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. package strfmt
  15. import (
  16. "database/sql/driver"
  17. "encoding/base64"
  18. "fmt"
  19. "net/url"
  20. "regexp"
  21. "strings"
  22. "github.com/asaskevich/govalidator"
  23. "github.com/mailru/easyjson/jlexer"
  24. "github.com/mailru/easyjson/jwriter"
  25. )
  26. const (
  27. // HostnamePattern http://json-schema.org/latest/json-schema-validation.html#anchor114
  28. // A string instance is valid against this attribute if it is a valid
  29. // representation for an Internet host name, as defined by RFC 1034, section 3.1 [RFC1034].
  30. // http://tools.ietf.org/html/rfc1034#section-3.5
  31. // <digit> ::= any one of the ten digits 0 through 9
  32. // var digit = /[0-9]/;
  33. // <letter> ::= any one of the 52 alphabetic characters A through Z in upper case and a through z in lower case
  34. // var letter = /[a-zA-Z]/;
  35. // <let-dig> ::= <letter> | <digit>
  36. // var letDig = /[0-9a-zA-Z]/;
  37. // <let-dig-hyp> ::= <let-dig> | "-"
  38. // var letDigHyp = /[-0-9a-zA-Z]/;
  39. // <ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>
  40. // var ldhStr = /[-0-9a-zA-Z]+/;
  41. // <label> ::= <letter> [ [ <ldh-str> ] <let-dig> ]
  42. // var label = /[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?/;
  43. // <subdomain> ::= <label> | <subdomain> "." <label>
  44. // var subdomain = /^[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?(\.[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?)*$/;
  45. // <domain> ::= <subdomain> | " "
  46. HostnamePattern = `^[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?(\.[a-zA-Z](([-0-9a-zA-Z]+)?[0-9a-zA-Z])?)*$`
  47. // UUIDPattern Regex for UUID that allows uppercase
  48. UUIDPattern = `(?i)^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`
  49. // UUID3Pattern Regex for UUID3 that allows uppercase
  50. UUID3Pattern = `(?i)^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12}$`
  51. // UUID4Pattern Regex for UUID4 that allows uppercase
  52. UUID4Pattern = `(?i)^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$`
  53. // UUID5Pattern Regex for UUID5 that allows uppercase
  54. UUID5Pattern = `(?i)^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$`
  55. )
  56. var (
  57. rxHostname = regexp.MustCompile(HostnamePattern)
  58. rxUUID = regexp.MustCompile(UUIDPattern)
  59. rxUUID3 = regexp.MustCompile(UUID3Pattern)
  60. rxUUID4 = regexp.MustCompile(UUID4Pattern)
  61. rxUUID5 = regexp.MustCompile(UUID5Pattern)
  62. )
  63. // IsStrictURI returns true when the string is an absolute URI
  64. func IsStrictURI(str string) bool {
  65. _, err := url.ParseRequestURI(str)
  66. return err == nil
  67. }
  68. // IsHostname returns true when the string is a valid hostname
  69. func IsHostname(str string) bool {
  70. if !rxHostname.MatchString(str) {
  71. return false
  72. }
  73. // the sum of all label octets and label lengths is limited to 255.
  74. if len(str) > 255 {
  75. return false
  76. }
  77. // Each node has a label, which is zero to 63 octets in length
  78. parts := strings.Split(str, ".")
  79. valid := true
  80. for _, p := range parts {
  81. if len(p) > 63 {
  82. valid = false
  83. }
  84. }
  85. return valid
  86. }
  87. // IsUUID returns true is the string matches a UUID, upper case is allowed
  88. func IsUUID(str string) bool {
  89. return rxUUID.MatchString(str)
  90. }
  91. // IsUUID3 returns true is the string matches a UUID, upper case is allowed
  92. func IsUUID3(str string) bool {
  93. return rxUUID3.MatchString(str)
  94. }
  95. // IsUUID4 returns true is the string matches a UUID, upper case is allowed
  96. func IsUUID4(str string) bool {
  97. return rxUUID4.MatchString(str)
  98. }
  99. // IsUUID5 returns true is the string matches a UUID, upper case is allowed
  100. func IsUUID5(str string) bool {
  101. return rxUUID5.MatchString(str)
  102. }
  103. func init() {
  104. u := URI("")
  105. Default.Add("uri", &u, IsStrictURI)
  106. eml := Email("")
  107. Default.Add("email", &eml, govalidator.IsEmail)
  108. hn := Hostname("")
  109. Default.Add("hostname", &hn, IsHostname)
  110. ip4 := IPv4("")
  111. Default.Add("ipv4", &ip4, govalidator.IsIPv4)
  112. ip6 := IPv6("")
  113. Default.Add("ipv6", &ip6, govalidator.IsIPv6)
  114. mac := MAC("")
  115. Default.Add("mac", &mac, govalidator.IsMAC)
  116. uid := UUID("")
  117. Default.Add("uuid", &uid, IsUUID)
  118. uid3 := UUID3("")
  119. Default.Add("uuid3", &uid3, IsUUID3)
  120. uid4 := UUID4("")
  121. Default.Add("uuid4", &uid4, IsUUID4)
  122. uid5 := UUID5("")
  123. Default.Add("uuid5", &uid5, IsUUID5)
  124. isbn := ISBN("")
  125. Default.Add("isbn", &isbn, func(str string) bool { return govalidator.IsISBN10(str) || govalidator.IsISBN13(str) })
  126. isbn10 := ISBN10("")
  127. Default.Add("isbn10", &isbn10, govalidator.IsISBN10)
  128. isbn13 := ISBN13("")
  129. Default.Add("isbn13", &isbn13, govalidator.IsISBN13)
  130. cc := CreditCard("")
  131. Default.Add("creditcard", &cc, govalidator.IsCreditCard)
  132. ssn := SSN("")
  133. Default.Add("ssn", &ssn, govalidator.IsSSN)
  134. hc := HexColor("")
  135. Default.Add("hexcolor", &hc, govalidator.IsHexcolor)
  136. rc := RGBColor("")
  137. Default.Add("rgbcolor", &rc, govalidator.IsRGBcolor)
  138. b64 := Base64([]byte(nil))
  139. Default.Add("byte", &b64, govalidator.IsBase64)
  140. pw := Password("")
  141. Default.Add("password", &pw, func(_ string) bool { return true })
  142. }
  143. var formatCheckers = map[string]Validator{
  144. "byte": govalidator.IsBase64,
  145. }
  146. // Base64 represents a base64 encoded string
  147. //
  148. // swagger:strfmt byte
  149. type Base64 []byte
  150. // MarshalText turns this instance into text
  151. func (b Base64) MarshalText() ([]byte, error) {
  152. enc := base64.URLEncoding
  153. src := []byte(b)
  154. buf := make([]byte, enc.EncodedLen(len(src)))
  155. enc.Encode(buf, src)
  156. return buf, nil
  157. }
  158. // UnmarshalText hydrates this instance from text
  159. func (b *Base64) UnmarshalText(data []byte) error { // validation is performed later on
  160. enc := base64.URLEncoding
  161. dbuf := make([]byte, enc.DecodedLen(len(data)))
  162. n, err := enc.Decode(dbuf, data)
  163. if err != nil {
  164. return err
  165. }
  166. *b = dbuf[:n]
  167. return nil
  168. }
  169. // Scan read a value from a database driver
  170. func (b *Base64) Scan(raw interface{}) error {
  171. switch v := raw.(type) {
  172. case []byte:
  173. *b = Base64(string(v))
  174. case string:
  175. *b = Base64(v)
  176. default:
  177. return fmt.Errorf("cannot sql.Scan() strfmt.Base64 from: %#v", v)
  178. }
  179. return nil
  180. }
  181. // Value converts a value to a database driver value
  182. func (b Base64) Value() (driver.Value, error) {
  183. return driver.Value(string(b)), nil
  184. }
  185. func (b Base64) String() string {
  186. return string(b)
  187. }
  188. func (b Base64) MarshalJSON() ([]byte, error) {
  189. var w jwriter.Writer
  190. b.MarshalEasyJSON(&w)
  191. return w.BuildBytes()
  192. }
  193. func (b Base64) MarshalEasyJSON(w *jwriter.Writer) {
  194. w.String(base64.StdEncoding.EncodeToString([]byte(b)))
  195. }
  196. func (b *Base64) UnmarshalJSON(data []byte) error {
  197. l := jlexer.Lexer{Data: data}
  198. b.UnmarshalEasyJSON(&l)
  199. return l.Error()
  200. }
  201. func (b *Base64) UnmarshalEasyJSON(in *jlexer.Lexer) {
  202. if data := in.String(); in.Ok() {
  203. enc := base64.StdEncoding
  204. dbuf := make([]byte, enc.DecodedLen(len(data)))
  205. n, err := enc.Decode(dbuf, []byte(data))
  206. if err != nil {
  207. in.AddError(err)
  208. return
  209. }
  210. *b = dbuf[:n]
  211. }
  212. }
  213. // URI represents the uri string format as specified by the json schema spec
  214. //
  215. // swagger:strfmt uri
  216. type URI string
  217. // MarshalText turns this instance into text
  218. func (u URI) MarshalText() ([]byte, error) {
  219. return []byte(string(u)), nil
  220. }
  221. // UnmarshalText hydrates this instance from text
  222. func (u *URI) UnmarshalText(data []byte) error { // validation is performed later on
  223. *u = URI(string(data))
  224. return nil
  225. }
  226. // Scan read a value from a database driver
  227. func (u *URI) Scan(raw interface{}) error {
  228. switch v := raw.(type) {
  229. case []byte:
  230. *u = URI(string(v))
  231. case string:
  232. *u = URI(v)
  233. default:
  234. return fmt.Errorf("cannot sql.Scan() strfmt.URI from: %#v", v)
  235. }
  236. return nil
  237. }
  238. // Value converts a value to a database driver value
  239. func (u URI) Value() (driver.Value, error) {
  240. return driver.Value(string(u)), nil
  241. }
  242. func (u URI) String() string {
  243. return string(u)
  244. }
  245. func (u URI) MarshalJSON() ([]byte, error) {
  246. var w jwriter.Writer
  247. u.MarshalEasyJSON(&w)
  248. return w.BuildBytes()
  249. }
  250. func (u URI) MarshalEasyJSON(w *jwriter.Writer) {
  251. w.String(string(u))
  252. }
  253. func (u *URI) UnmarshalJSON(data []byte) error {
  254. l := jlexer.Lexer{Data: data}
  255. u.UnmarshalEasyJSON(&l)
  256. return l.Error()
  257. }
  258. func (u *URI) UnmarshalEasyJSON(in *jlexer.Lexer) {
  259. if data := in.String(); in.Ok() {
  260. *u = URI(data)
  261. }
  262. }
  263. // Email represents the email string format as specified by the json schema spec
  264. //
  265. // swagger:strfmt email
  266. type Email string
  267. // MarshalText turns this instance into text
  268. func (e Email) MarshalText() ([]byte, error) {
  269. return []byte(string(e)), nil
  270. }
  271. // UnmarshalText hydrates this instance from text
  272. func (e *Email) UnmarshalText(data []byte) error { // validation is performed later on
  273. *e = Email(string(data))
  274. return nil
  275. }
  276. // Scan read a value from a database driver
  277. func (e *Email) Scan(raw interface{}) error {
  278. switch v := raw.(type) {
  279. case []byte:
  280. *e = Email(string(v))
  281. case string:
  282. *e = Email(v)
  283. default:
  284. return fmt.Errorf("cannot sql.Scan() strfmt.Email from: %#v", v)
  285. }
  286. return nil
  287. }
  288. // Value converts a value to a database driver value
  289. func (e Email) Value() (driver.Value, error) {
  290. return driver.Value(string(e)), nil
  291. }
  292. func (e Email) String() string {
  293. return string(e)
  294. }
  295. func (e Email) MarshalJSON() ([]byte, error) {
  296. var w jwriter.Writer
  297. e.MarshalEasyJSON(&w)
  298. return w.BuildBytes()
  299. }
  300. func (e Email) MarshalEasyJSON(w *jwriter.Writer) {
  301. w.String(string(e))
  302. }
  303. func (e *Email) UnmarshalJSON(data []byte) error {
  304. l := jlexer.Lexer{Data: data}
  305. e.UnmarshalEasyJSON(&l)
  306. return l.Error()
  307. }
  308. func (e *Email) UnmarshalEasyJSON(in *jlexer.Lexer) {
  309. if data := in.String(); in.Ok() {
  310. *e = Email(data)
  311. }
  312. }
  313. // Hostname represents the hostname string format as specified by the json schema spec
  314. //
  315. // swagger:strfmt hostname
  316. type Hostname string
  317. // MarshalText turns this instance into text
  318. func (h Hostname) MarshalText() ([]byte, error) {
  319. return []byte(string(h)), nil
  320. }
  321. // UnmarshalText hydrates this instance from text
  322. func (h *Hostname) UnmarshalText(data []byte) error { // validation is performed later on
  323. *h = Hostname(string(data))
  324. return nil
  325. }
  326. // Scan read a value from a database driver
  327. func (h *Hostname) Scan(raw interface{}) error {
  328. switch v := raw.(type) {
  329. case []byte:
  330. *h = Hostname(string(v))
  331. case string:
  332. *h = Hostname(v)
  333. default:
  334. return fmt.Errorf("cannot sql.Scan() strfmt.Hostname from: %#v", v)
  335. }
  336. return nil
  337. }
  338. // Value converts a value to a database driver value
  339. func (h Hostname) Value() (driver.Value, error) {
  340. return driver.Value(string(h)), nil
  341. }
  342. func (h Hostname) String() string {
  343. return string(h)
  344. }
  345. func (h Hostname) MarshalJSON() ([]byte, error) {
  346. var w jwriter.Writer
  347. h.MarshalEasyJSON(&w)
  348. return w.BuildBytes()
  349. }
  350. func (h Hostname) MarshalEasyJSON(w *jwriter.Writer) {
  351. w.String(string(h))
  352. }
  353. func (h *Hostname) UnmarshalJSON(data []byte) error {
  354. l := jlexer.Lexer{Data: data}
  355. h.UnmarshalEasyJSON(&l)
  356. return l.Error()
  357. }
  358. func (h *Hostname) UnmarshalEasyJSON(in *jlexer.Lexer) {
  359. if data := in.String(); in.Ok() {
  360. *h = Hostname(data)
  361. }
  362. }
  363. // IPv4 represents an IP v4 address
  364. //
  365. // swagger:strfmt ipv4
  366. type IPv4 string
  367. // MarshalText turns this instance into text
  368. func (u IPv4) MarshalText() ([]byte, error) {
  369. return []byte(string(u)), nil
  370. }
  371. // UnmarshalText hydrates this instance from text
  372. func (u *IPv4) UnmarshalText(data []byte) error { // validation is performed later on
  373. *u = IPv4(string(data))
  374. return nil
  375. }
  376. // Scan read a value from a database driver
  377. func (u *IPv4) Scan(raw interface{}) error {
  378. switch v := raw.(type) {
  379. case []byte:
  380. *u = IPv4(string(v))
  381. case string:
  382. *u = IPv4(v)
  383. default:
  384. return fmt.Errorf("cannot sql.Scan() strfmt.IPv4 from: %#v", v)
  385. }
  386. return nil
  387. }
  388. // Value converts a value to a database driver value
  389. func (u IPv4) Value() (driver.Value, error) {
  390. return driver.Value(string(u)), nil
  391. }
  392. func (u IPv4) String() string {
  393. return string(u)
  394. }
  395. func (u IPv4) MarshalJSON() ([]byte, error) {
  396. var w jwriter.Writer
  397. u.MarshalEasyJSON(&w)
  398. return w.BuildBytes()
  399. }
  400. func (u IPv4) MarshalEasyJSON(w *jwriter.Writer) {
  401. w.String(string(u))
  402. }
  403. func (u *IPv4) UnmarshalJSON(data []byte) error {
  404. l := jlexer.Lexer{Data: data}
  405. u.UnmarshalEasyJSON(&l)
  406. return l.Error()
  407. }
  408. func (u *IPv4) UnmarshalEasyJSON(in *jlexer.Lexer) {
  409. if data := in.String(); in.Ok() {
  410. *u = IPv4(data)
  411. }
  412. }
  413. // IPv6 represents an IP v6 address
  414. //
  415. // swagger:strfmt ipv6
  416. type IPv6 string
  417. // MarshalText turns this instance into text
  418. func (u IPv6) MarshalText() ([]byte, error) {
  419. return []byte(string(u)), nil
  420. }
  421. // UnmarshalText hydrates this instance from text
  422. func (u *IPv6) UnmarshalText(data []byte) error { // validation is performed later on
  423. *u = IPv6(string(data))
  424. return nil
  425. }
  426. // Scan read a value from a database driver
  427. func (u *IPv6) Scan(raw interface{}) error {
  428. switch v := raw.(type) {
  429. case []byte:
  430. *u = IPv6(string(v))
  431. case string:
  432. *u = IPv6(v)
  433. default:
  434. return fmt.Errorf("cannot sql.Scan() strfmt.IPv6 from: %#v", v)
  435. }
  436. return nil
  437. }
  438. // Value converts a value to a database driver value
  439. func (u IPv6) Value() (driver.Value, error) {
  440. return driver.Value(string(u)), nil
  441. }
  442. func (u IPv6) String() string {
  443. return string(u)
  444. }
  445. func (u IPv6) MarshalJSON() ([]byte, error) {
  446. var w jwriter.Writer
  447. u.MarshalEasyJSON(&w)
  448. return w.BuildBytes()
  449. }
  450. func (u IPv6) MarshalEasyJSON(w *jwriter.Writer) {
  451. w.String(string(u))
  452. }
  453. func (u *IPv6) UnmarshalJSON(data []byte) error {
  454. l := jlexer.Lexer{Data: data}
  455. u.UnmarshalEasyJSON(&l)
  456. return l.Error()
  457. }
  458. func (u *IPv6) UnmarshalEasyJSON(in *jlexer.Lexer) {
  459. if data := in.String(); in.Ok() {
  460. *u = IPv6(data)
  461. }
  462. }
  463. // MAC represents a 48 bit MAC address
  464. //
  465. // swagger:strfmt mac
  466. type MAC string
  467. // MarshalText turns this instance into text
  468. func (u MAC) MarshalText() ([]byte, error) {
  469. return []byte(string(u)), nil
  470. }
  471. // UnmarshalText hydrates this instance from text
  472. func (u *MAC) UnmarshalText(data []byte) error { // validation is performed later on
  473. *u = MAC(string(data))
  474. return nil
  475. }
  476. // Scan read a value from a database driver
  477. func (u *MAC) Scan(raw interface{}) error {
  478. switch v := raw.(type) {
  479. case []byte:
  480. *u = MAC(string(v))
  481. case string:
  482. *u = MAC(v)
  483. default:
  484. return fmt.Errorf("cannot sql.Scan() strfmt.IPv4 from: %#v", v)
  485. }
  486. return nil
  487. }
  488. // Value converts a value to a database driver value
  489. func (u MAC) Value() (driver.Value, error) {
  490. return driver.Value(string(u)), nil
  491. }
  492. func (u MAC) String() string {
  493. return string(u)
  494. }
  495. func (u MAC) MarshalJSON() ([]byte, error) {
  496. var w jwriter.Writer
  497. u.MarshalEasyJSON(&w)
  498. return w.BuildBytes()
  499. }
  500. func (u MAC) MarshalEasyJSON(w *jwriter.Writer) {
  501. w.String(string(u))
  502. }
  503. func (u *MAC) UnmarshalJSON(data []byte) error {
  504. l := jlexer.Lexer{Data: data}
  505. u.UnmarshalEasyJSON(&l)
  506. return l.Error()
  507. }
  508. func (u *MAC) UnmarshalEasyJSON(in *jlexer.Lexer) {
  509. if data := in.String(); in.Ok() {
  510. *u = MAC(data)
  511. }
  512. }
  513. // UUID represents a uuid string format
  514. //
  515. // swagger:strfmt uuid
  516. type UUID string
  517. // MarshalText turns this instance into text
  518. func (u UUID) MarshalText() ([]byte, error) {
  519. return []byte(string(u)), nil
  520. }
  521. // UnmarshalText hydrates this instance from text
  522. func (u *UUID) UnmarshalText(data []byte) error { // validation is performed later on
  523. *u = UUID(string(data))
  524. return nil
  525. }
  526. // Scan read a value from a database driver
  527. func (u *UUID) Scan(raw interface{}) error {
  528. switch v := raw.(type) {
  529. case []byte:
  530. *u = UUID(string(v))
  531. case string:
  532. *u = UUID(v)
  533. default:
  534. return fmt.Errorf("cannot sql.Scan() strfmt.UUID from: %#v", v)
  535. }
  536. return nil
  537. }
  538. // Value converts a value to a database driver value
  539. func (u UUID) Value() (driver.Value, error) {
  540. return driver.Value(string(u)), nil
  541. }
  542. func (u UUID) String() string {
  543. return string(u)
  544. }
  545. func (u UUID) MarshalJSON() ([]byte, error) {
  546. var w jwriter.Writer
  547. u.MarshalEasyJSON(&w)
  548. return w.BuildBytes()
  549. }
  550. func (u UUID) MarshalEasyJSON(w *jwriter.Writer) {
  551. w.String(string(u))
  552. }
  553. func (u *UUID) UnmarshalJSON(data []byte) error {
  554. l := jlexer.Lexer{Data: data}
  555. u.UnmarshalEasyJSON(&l)
  556. return l.Error()
  557. }
  558. func (u *UUID) UnmarshalEasyJSON(in *jlexer.Lexer) {
  559. if data := in.String(); in.Ok() {
  560. *u = UUID(data)
  561. }
  562. }
  563. // UUID3 represents a uuid3 string format
  564. //
  565. // swagger:strfmt uuid3
  566. type UUID3 string
  567. // MarshalText turns this instance into text
  568. func (u UUID3) MarshalText() ([]byte, error) {
  569. return []byte(string(u)), nil
  570. }
  571. // UnmarshalText hydrates this instance from text
  572. func (u *UUID3) UnmarshalText(data []byte) error { // validation is performed later on
  573. *u = UUID3(string(data))
  574. return nil
  575. }
  576. // Scan read a value from a database driver
  577. func (u *UUID3) Scan(raw interface{}) error {
  578. switch v := raw.(type) {
  579. case []byte:
  580. *u = UUID3(string(v))
  581. case string:
  582. *u = UUID3(v)
  583. default:
  584. return fmt.Errorf("cannot sql.Scan() strfmt.UUID3 from: %#v", v)
  585. }
  586. return nil
  587. }
  588. // Value converts a value to a database driver value
  589. func (u UUID3) Value() (driver.Value, error) {
  590. return driver.Value(string(u)), nil
  591. }
  592. func (u UUID3) String() string {
  593. return string(u)
  594. }
  595. func (u UUID3) MarshalJSON() ([]byte, error) {
  596. var w jwriter.Writer
  597. u.MarshalEasyJSON(&w)
  598. return w.BuildBytes()
  599. }
  600. func (u UUID3) MarshalEasyJSON(w *jwriter.Writer) {
  601. w.String(string(u))
  602. }
  603. func (u *UUID3) UnmarshalJSON(data []byte) error {
  604. l := jlexer.Lexer{Data: data}
  605. u.UnmarshalEasyJSON(&l)
  606. return l.Error()
  607. }
  608. func (u *UUID3) UnmarshalEasyJSON(in *jlexer.Lexer) {
  609. if data := in.String(); in.Ok() {
  610. *u = UUID3(data)
  611. }
  612. }
  613. // UUID4 represents a uuid4 string format
  614. //
  615. // swagger:strfmt uuid4
  616. type UUID4 string
  617. // MarshalText turns this instance into text
  618. func (u UUID4) MarshalText() ([]byte, error) {
  619. return []byte(string(u)), nil
  620. }
  621. // UnmarshalText hydrates this instance from text
  622. func (u *UUID4) UnmarshalText(data []byte) error { // validation is performed later on
  623. *u = UUID4(string(data))
  624. return nil
  625. }
  626. // Scan read a value from a database driver
  627. func (u *UUID4) Scan(raw interface{}) error {
  628. switch v := raw.(type) {
  629. case []byte:
  630. *u = UUID4(string(v))
  631. case string:
  632. *u = UUID4(v)
  633. default:
  634. return fmt.Errorf("cannot sql.Scan() strfmt.UUID4 from: %#v", v)
  635. }
  636. return nil
  637. }
  638. // Value converts a value to a database driver value
  639. func (u UUID4) Value() (driver.Value, error) {
  640. return driver.Value(string(u)), nil
  641. }
  642. func (u UUID4) String() string {
  643. return string(u)
  644. }
  645. func (u UUID4) MarshalJSON() ([]byte, error) {
  646. var w jwriter.Writer
  647. u.MarshalEasyJSON(&w)
  648. return w.BuildBytes()
  649. }
  650. func (u UUID4) MarshalEasyJSON(w *jwriter.Writer) {
  651. w.String(string(u))
  652. }
  653. func (u *UUID4) UnmarshalJSON(data []byte) error {
  654. l := jlexer.Lexer{Data: data}
  655. u.UnmarshalEasyJSON(&l)
  656. return l.Error()
  657. }
  658. func (u *UUID4) UnmarshalEasyJSON(in *jlexer.Lexer) {
  659. if data := in.String(); in.Ok() {
  660. *u = UUID4(data)
  661. }
  662. }
  663. // UUID5 represents a uuid5 string format
  664. //
  665. // swagger:strfmt uuid5
  666. type UUID5 string
  667. // MarshalText turns this instance into text
  668. func (u UUID5) MarshalText() ([]byte, error) {
  669. return []byte(string(u)), nil
  670. }
  671. // UnmarshalText hydrates this instance from text
  672. func (u *UUID5) UnmarshalText(data []byte) error { // validation is performed later on
  673. *u = UUID5(string(data))
  674. return nil
  675. }
  676. // Scan read a value from a database driver
  677. func (u *UUID5) Scan(raw interface{}) error {
  678. switch v := raw.(type) {
  679. case []byte:
  680. *u = UUID5(string(v))
  681. case string:
  682. *u = UUID5(v)
  683. default:
  684. return fmt.Errorf("cannot sql.Scan() strfmt.UUID5 from: %#v", v)
  685. }
  686. return nil
  687. }
  688. // Value converts a value to a database driver value
  689. func (u UUID5) Value() (driver.Value, error) {
  690. return driver.Value(string(u)), nil
  691. }
  692. func (u UUID5) String() string {
  693. return string(u)
  694. }
  695. func (u UUID5) MarshalJSON() ([]byte, error) {
  696. var w jwriter.Writer
  697. u.MarshalEasyJSON(&w)
  698. return w.BuildBytes()
  699. }
  700. func (u UUID5) MarshalEasyJSON(w *jwriter.Writer) {
  701. w.String(string(u))
  702. }
  703. func (u *UUID5) UnmarshalJSON(data []byte) error {
  704. l := jlexer.Lexer{Data: data}
  705. u.UnmarshalEasyJSON(&l)
  706. return l.Error()
  707. }
  708. func (u *UUID5) UnmarshalEasyJSON(in *jlexer.Lexer) {
  709. if data := in.String(); in.Ok() {
  710. *u = UUID5(data)
  711. }
  712. }
  713. // ISBN represents an isbn string format
  714. //
  715. // swagger:strfmt isbn
  716. type ISBN string
  717. // MarshalText turns this instance into text
  718. func (u ISBN) MarshalText() ([]byte, error) {
  719. return []byte(string(u)), nil
  720. }
  721. // UnmarshalText hydrates this instance from text
  722. func (u *ISBN) UnmarshalText(data []byte) error { // validation is performed later on
  723. *u = ISBN(string(data))
  724. return nil
  725. }
  726. // Scan read a value from a database driver
  727. func (u *ISBN) Scan(raw interface{}) error {
  728. switch v := raw.(type) {
  729. case []byte:
  730. *u = ISBN(string(v))
  731. case string:
  732. *u = ISBN(v)
  733. default:
  734. return fmt.Errorf("cannot sql.Scan() strfmt.ISBN from: %#v", v)
  735. }
  736. return nil
  737. }
  738. // Value converts a value to a database driver value
  739. func (u ISBN) Value() (driver.Value, error) {
  740. return driver.Value(string(u)), nil
  741. }
  742. func (u ISBN) String() string {
  743. return string(u)
  744. }
  745. func (u ISBN) MarshalJSON() ([]byte, error) {
  746. var w jwriter.Writer
  747. u.MarshalEasyJSON(&w)
  748. return w.BuildBytes()
  749. }
  750. func (u ISBN) MarshalEasyJSON(w *jwriter.Writer) {
  751. w.String(string(u))
  752. }
  753. func (u *ISBN) UnmarshalJSON(data []byte) error {
  754. l := jlexer.Lexer{Data: data}
  755. u.UnmarshalEasyJSON(&l)
  756. return l.Error()
  757. }
  758. func (u *ISBN) UnmarshalEasyJSON(in *jlexer.Lexer) {
  759. if data := in.String(); in.Ok() {
  760. *u = ISBN(data)
  761. }
  762. }
  763. // ISBN10 represents an isbn 10 string format
  764. //
  765. // swagger:strfmt isbn10
  766. type ISBN10 string
  767. // MarshalText turns this instance into text
  768. func (u ISBN10) MarshalText() ([]byte, error) {
  769. return []byte(string(u)), nil
  770. }
  771. // UnmarshalText hydrates this instance from text
  772. func (u *ISBN10) UnmarshalText(data []byte) error { // validation is performed later on
  773. *u = ISBN10(string(data))
  774. return nil
  775. }
  776. // Scan read a value from a database driver
  777. func (u *ISBN10) Scan(raw interface{}) error {
  778. switch v := raw.(type) {
  779. case []byte:
  780. *u = ISBN10(string(v))
  781. case string:
  782. *u = ISBN10(v)
  783. default:
  784. return fmt.Errorf("cannot sql.Scan() strfmt.ISBN10 from: %#v", v)
  785. }
  786. return nil
  787. }
  788. // Value converts a value to a database driver value
  789. func (u ISBN10) Value() (driver.Value, error) {
  790. return driver.Value(string(u)), nil
  791. }
  792. func (u ISBN10) String() string {
  793. return string(u)
  794. }
  795. func (u ISBN10) MarshalJSON() ([]byte, error) {
  796. var w jwriter.Writer
  797. u.MarshalEasyJSON(&w)
  798. return w.BuildBytes()
  799. }
  800. func (u ISBN10) MarshalEasyJSON(w *jwriter.Writer) {
  801. w.String(string(u))
  802. }
  803. func (u *ISBN10) UnmarshalJSON(data []byte) error {
  804. l := jlexer.Lexer{Data: data}
  805. u.UnmarshalEasyJSON(&l)
  806. return l.Error()
  807. }
  808. func (u *ISBN10) UnmarshalEasyJSON(in *jlexer.Lexer) {
  809. if data := in.String(); in.Ok() {
  810. *u = ISBN10(data)
  811. }
  812. }
  813. // ISBN13 represents an isbn 13 string format
  814. //
  815. // swagger:strfmt isbn13
  816. type ISBN13 string
  817. // MarshalText turns this instance into text
  818. func (u ISBN13) MarshalText() ([]byte, error) {
  819. return []byte(string(u)), nil
  820. }
  821. // UnmarshalText hydrates this instance from text
  822. func (u *ISBN13) UnmarshalText(data []byte) error { // validation is performed later on
  823. *u = ISBN13(string(data))
  824. return nil
  825. }
  826. // Scan read a value from a database driver
  827. func (u *ISBN13) Scan(raw interface{}) error {
  828. switch v := raw.(type) {
  829. case []byte:
  830. *u = ISBN13(string(v))
  831. case string:
  832. *u = ISBN13(v)
  833. default:
  834. return fmt.Errorf("cannot sql.Scan() strfmt.ISBN13 from: %#v", v)
  835. }
  836. return nil
  837. }
  838. // Value converts a value to a database driver value
  839. func (u ISBN13) Value() (driver.Value, error) {
  840. return driver.Value(string(u)), nil
  841. }
  842. func (u ISBN13) String() string {
  843. return string(u)
  844. }
  845. func (u ISBN13) MarshalJSON() ([]byte, error) {
  846. var w jwriter.Writer
  847. u.MarshalEasyJSON(&w)
  848. return w.BuildBytes()
  849. }
  850. func (u ISBN13) MarshalEasyJSON(w *jwriter.Writer) {
  851. w.String(string(u))
  852. }
  853. func (u *ISBN13) UnmarshalJSON(data []byte) error {
  854. l := jlexer.Lexer{Data: data}
  855. u.UnmarshalEasyJSON(&l)
  856. return l.Error()
  857. }
  858. func (u *ISBN13) UnmarshalEasyJSON(in *jlexer.Lexer) {
  859. if data := in.String(); in.Ok() {
  860. *u = ISBN13(data)
  861. }
  862. }
  863. // CreditCard represents a credit card string format
  864. //
  865. // swagger:strfmt creditcard
  866. type CreditCard string
  867. // MarshalText turns this instance into text
  868. func (u CreditCard) MarshalText() ([]byte, error) {
  869. return []byte(string(u)), nil
  870. }
  871. // UnmarshalText hydrates this instance from text
  872. func (u *CreditCard) UnmarshalText(data []byte) error { // validation is performed later on
  873. *u = CreditCard(string(data))
  874. return nil
  875. }
  876. // Scan read a value from a database driver
  877. func (u *CreditCard) Scan(raw interface{}) error {
  878. switch v := raw.(type) {
  879. case []byte:
  880. *u = CreditCard(string(v))
  881. case string:
  882. *u = CreditCard(v)
  883. default:
  884. return fmt.Errorf("cannot sql.Scan() strfmt.CreditCard from: %#v", v)
  885. }
  886. return nil
  887. }
  888. // Value converts a value to a database driver value
  889. func (u CreditCard) Value() (driver.Value, error) {
  890. return driver.Value(string(u)), nil
  891. }
  892. func (u CreditCard) String() string {
  893. return string(u)
  894. }
  895. func (u CreditCard) MarshalJSON() ([]byte, error) {
  896. var w jwriter.Writer
  897. u.MarshalEasyJSON(&w)
  898. return w.BuildBytes()
  899. }
  900. func (u CreditCard) MarshalEasyJSON(w *jwriter.Writer) {
  901. w.String(string(u))
  902. }
  903. func (u *CreditCard) UnmarshalJSON(data []byte) error {
  904. l := jlexer.Lexer{Data: data}
  905. u.UnmarshalEasyJSON(&l)
  906. return l.Error()
  907. }
  908. func (u *CreditCard) UnmarshalEasyJSON(in *jlexer.Lexer) {
  909. if data := in.String(); in.Ok() {
  910. *u = CreditCard(data)
  911. }
  912. }
  913. // SSN represents a social security string format
  914. //
  915. // swagger:strfmt ssn
  916. type SSN string
  917. // MarshalText turns this instance into text
  918. func (u SSN) MarshalText() ([]byte, error) {
  919. return []byte(string(u)), nil
  920. }
  921. // UnmarshalText hydrates this instance from text
  922. func (u *SSN) UnmarshalText(data []byte) error { // validation is performed later on
  923. *u = SSN(string(data))
  924. return nil
  925. }
  926. // Scan read a value from a database driver
  927. func (u *SSN) Scan(raw interface{}) error {
  928. switch v := raw.(type) {
  929. case []byte:
  930. *u = SSN(string(v))
  931. case string:
  932. *u = SSN(v)
  933. default:
  934. return fmt.Errorf("cannot sql.Scan() strfmt.SSN from: %#v", v)
  935. }
  936. return nil
  937. }
  938. // Value converts a value to a database driver value
  939. func (u SSN) Value() (driver.Value, error) {
  940. return driver.Value(string(u)), nil
  941. }
  942. func (u SSN) String() string {
  943. return string(u)
  944. }
  945. func (u SSN) MarshalJSON() ([]byte, error) {
  946. var w jwriter.Writer
  947. u.MarshalEasyJSON(&w)
  948. return w.BuildBytes()
  949. }
  950. func (u SSN) MarshalEasyJSON(w *jwriter.Writer) {
  951. w.String(string(u))
  952. }
  953. func (u *SSN) UnmarshalJSON(data []byte) error {
  954. l := jlexer.Lexer{Data: data}
  955. u.UnmarshalEasyJSON(&l)
  956. return l.Error()
  957. }
  958. func (u *SSN) UnmarshalEasyJSON(in *jlexer.Lexer) {
  959. if data := in.String(); in.Ok() {
  960. *u = SSN(data)
  961. }
  962. }
  963. // HexColor represents a hex color string format
  964. //
  965. // swagger:strfmt hexcolor
  966. type HexColor string
  967. // MarshalText turns this instance into text
  968. func (h HexColor) MarshalText() ([]byte, error) {
  969. return []byte(string(h)), nil
  970. }
  971. // UnmarshalText hydrates this instance from text
  972. func (h *HexColor) UnmarshalText(data []byte) error { // validation is performed later on
  973. *h = HexColor(string(data))
  974. return nil
  975. }
  976. // Scan read a value from a database driver
  977. func (h *HexColor) Scan(raw interface{}) error {
  978. switch v := raw.(type) {
  979. case []byte:
  980. *h = HexColor(string(v))
  981. case string:
  982. *h = HexColor(v)
  983. default:
  984. return fmt.Errorf("cannot sql.Scan() strfmt.HexColor from: %#v", v)
  985. }
  986. return nil
  987. }
  988. // Value converts a value to a database driver value
  989. func (h HexColor) Value() (driver.Value, error) {
  990. return driver.Value(string(h)), nil
  991. }
  992. func (h HexColor) String() string {
  993. return string(h)
  994. }
  995. func (h HexColor) MarshalJSON() ([]byte, error) {
  996. var w jwriter.Writer
  997. h.MarshalEasyJSON(&w)
  998. return w.BuildBytes()
  999. }
  1000. func (h HexColor) MarshalEasyJSON(w *jwriter.Writer) {
  1001. w.String(string(h))
  1002. }
  1003. func (h *HexColor) UnmarshalJSON(data []byte) error {
  1004. l := jlexer.Lexer{Data: data}
  1005. h.UnmarshalEasyJSON(&l)
  1006. return l.Error()
  1007. }
  1008. func (h *HexColor) UnmarshalEasyJSON(in *jlexer.Lexer) {
  1009. if data := in.String(); in.Ok() {
  1010. *h = HexColor(data)
  1011. }
  1012. }
  1013. // RGBColor represents a RGB color string format
  1014. //
  1015. // swagger:strfmt rgbcolor
  1016. type RGBColor string
  1017. // MarshalText turns this instance into text
  1018. func (r RGBColor) MarshalText() ([]byte, error) {
  1019. return []byte(string(r)), nil
  1020. }
  1021. // UnmarshalText hydrates this instance from text
  1022. func (r *RGBColor) UnmarshalText(data []byte) error { // validation is performed later on
  1023. *r = RGBColor(string(data))
  1024. return nil
  1025. }
  1026. // Scan read a value from a database driver
  1027. func (r *RGBColor) Scan(raw interface{}) error {
  1028. switch v := raw.(type) {
  1029. case []byte:
  1030. *r = RGBColor(string(v))
  1031. case string:
  1032. *r = RGBColor(v)
  1033. default:
  1034. return fmt.Errorf("cannot sql.Scan() strfmt.RGBColor from: %#v", v)
  1035. }
  1036. return nil
  1037. }
  1038. // Value converts a value to a database driver value
  1039. func (r RGBColor) Value() (driver.Value, error) {
  1040. return driver.Value(string(r)), nil
  1041. }
  1042. func (r RGBColor) String() string {
  1043. return string(r)
  1044. }
  1045. func (r RGBColor) MarshalJSON() ([]byte, error) {
  1046. var w jwriter.Writer
  1047. r.MarshalEasyJSON(&w)
  1048. return w.BuildBytes()
  1049. }
  1050. func (r RGBColor) MarshalEasyJSON(w *jwriter.Writer) {
  1051. w.String(string(r))
  1052. }
  1053. func (r *RGBColor) UnmarshalJSON(data []byte) error {
  1054. l := jlexer.Lexer{Data: data}
  1055. r.UnmarshalEasyJSON(&l)
  1056. return l.Error()
  1057. }
  1058. func (r *RGBColor) UnmarshalEasyJSON(in *jlexer.Lexer) {
  1059. if data := in.String(); in.Ok() {
  1060. *r = RGBColor(data)
  1061. }
  1062. }
  1063. // Password represents a password.
  1064. // This has no validations and is mainly used as a marker for UI components.
  1065. //
  1066. // swagger:strfmt password
  1067. type Password string
  1068. // MarshalText turns this instance into text
  1069. func (r Password) MarshalText() ([]byte, error) {
  1070. return []byte(string(r)), nil
  1071. }
  1072. // UnmarshalText hydrates this instance from text
  1073. func (r *Password) UnmarshalText(data []byte) error { // validation is performed later on
  1074. *r = Password(string(data))
  1075. return nil
  1076. }
  1077. // Scan read a value from a database driver
  1078. func (r *Password) Scan(raw interface{}) error {
  1079. switch v := raw.(type) {
  1080. case []byte:
  1081. *r = Password(string(v))
  1082. case string:
  1083. *r = Password(v)
  1084. default:
  1085. return fmt.Errorf("cannot sql.Scan() strfmt.Password from: %#v", v)
  1086. }
  1087. return nil
  1088. }
  1089. // Value converts a value to a database driver value
  1090. func (r Password) Value() (driver.Value, error) {
  1091. return driver.Value(string(r)), nil
  1092. }
  1093. func (r Password) String() string {
  1094. return string(r)
  1095. }
  1096. func (r Password) MarshalJSON() ([]byte, error) {
  1097. var w jwriter.Writer
  1098. r.MarshalEasyJSON(&w)
  1099. return w.BuildBytes()
  1100. }
  1101. func (r Password) MarshalEasyJSON(w *jwriter.Writer) {
  1102. w.String(string(r))
  1103. }
  1104. func (r *Password) UnmarshalJSON(data []byte) error {
  1105. l := jlexer.Lexer{Data: data}
  1106. r.UnmarshalEasyJSON(&l)
  1107. return l.Error()
  1108. }
  1109. func (r *Password) UnmarshalEasyJSON(in *jlexer.Lexer) {
  1110. if data := in.String(); in.Ok() {
  1111. *r = Password(data)
  1112. }
  1113. }