default.go 43 KB

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