You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

default.go 46KB

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