1package govalidator
2
3import (
4	"reflect"
5	"regexp"
6	"sort"
7	"sync"
8)
9
10// Validator is a wrapper for a validator function that returns bool and accepts string.
11type Validator func(str string) bool
12
13// CustomTypeValidator is a wrapper for validator functions that returns bool and accepts any type.
14// The second parameter should be the context (in the case of validating a struct: the whole object being validated).
15type CustomTypeValidator func(i interface{}, o interface{}) bool
16
17// ParamValidator is a wrapper for validator functions that accept additional parameters.
18type ParamValidator func(str string, params ...string) bool
19
20// InterfaceParamValidator is a wrapper for functions that accept variants parameters for an interface value
21type InterfaceParamValidator func(in interface{}, params ...string) bool
22type tagOptionsMap map[string]tagOption
23
24func (t tagOptionsMap) orderedKeys() []string {
25	var keys []string
26	for k := range t {
27		keys = append(keys, k)
28	}
29
30	sort.Slice(keys, func(a, b int) bool {
31		return t[keys[a]].order < t[keys[b]].order
32	})
33
34	return keys
35}
36
37type tagOption struct {
38	name               string
39	customErrorMessage string
40	order              int
41}
42
43// UnsupportedTypeError is a wrapper for reflect.Type
44type UnsupportedTypeError struct {
45	Type reflect.Type
46}
47
48// stringValues is a slice of reflect.Value holding *reflect.StringValue.
49// It implements the methods to sort by string.
50type stringValues []reflect.Value
51
52// InterfaceParamTagMap is a map of functions accept variants parameters for an interface value
53var InterfaceParamTagMap = map[string]InterfaceParamValidator{
54	"type": IsType,
55}
56
57// InterfaceParamTagRegexMap maps interface param tags to their respective regexes.
58var InterfaceParamTagRegexMap = map[string]*regexp.Regexp{
59	"type": regexp.MustCompile(`^type\((.*)\)$`),
60}
61
62// ParamTagMap is a map of functions accept variants parameters
63var ParamTagMap = map[string]ParamValidator{
64	"length":          ByteLength,
65	"range":           Range,
66	"runelength":      RuneLength,
67	"stringlength":    StringLength,
68	"matches":         StringMatches,
69	"in":              IsInRaw,
70	"rsapub":          IsRsaPub,
71	"minstringlength": MinStringLength,
72	"maxstringlength": MaxStringLength,
73}
74
75// ParamTagRegexMap maps param tags to their respective regexes.
76var ParamTagRegexMap = map[string]*regexp.Regexp{
77	"range":           regexp.MustCompile("^range\\((\\d+)\\|(\\d+)\\)$"),
78	"length":          regexp.MustCompile("^length\\((\\d+)\\|(\\d+)\\)$"),
79	"runelength":      regexp.MustCompile("^runelength\\((\\d+)\\|(\\d+)\\)$"),
80	"stringlength":    regexp.MustCompile("^stringlength\\((\\d+)\\|(\\d+)\\)$"),
81	"in":              regexp.MustCompile(`^in\((.*)\)`),
82	"matches":         regexp.MustCompile(`^matches\((.+)\)$`),
83	"rsapub":          regexp.MustCompile("^rsapub\\((\\d+)\\)$"),
84	"minstringlength": regexp.MustCompile("^minstringlength\\((\\d+)\\)$"),
85	"maxstringlength": regexp.MustCompile("^maxstringlength\\((\\d+)\\)$"),
86}
87
88type customTypeTagMap struct {
89	validators map[string]CustomTypeValidator
90
91	sync.RWMutex
92}
93
94func (tm *customTypeTagMap) Get(name string) (CustomTypeValidator, bool) {
95	tm.RLock()
96	defer tm.RUnlock()
97	v, ok := tm.validators[name]
98	return v, ok
99}
100
101func (tm *customTypeTagMap) Set(name string, ctv CustomTypeValidator) {
102	tm.Lock()
103	defer tm.Unlock()
104	tm.validators[name] = ctv
105}
106
107// CustomTypeTagMap is a map of functions that can be used as tags for ValidateStruct function.
108// Use this to validate compound or custom types that need to be handled as a whole, e.g.
109// `type UUID [16]byte` (this would be handled as an array of bytes).
110var CustomTypeTagMap = &customTypeTagMap{validators: make(map[string]CustomTypeValidator)}
111
112// TagMap is a map of functions, that can be used as tags for ValidateStruct function.
113var TagMap = map[string]Validator{
114	"email":              IsEmail,
115	"url":                IsURL,
116	"dialstring":         IsDialString,
117	"requrl":             IsRequestURL,
118	"requri":             IsRequestURI,
119	"alpha":              IsAlpha,
120	"utfletter":          IsUTFLetter,
121	"alphanum":           IsAlphanumeric,
122	"utfletternum":       IsUTFLetterNumeric,
123	"numeric":            IsNumeric,
124	"utfnumeric":         IsUTFNumeric,
125	"utfdigit":           IsUTFDigit,
126	"hexadecimal":        IsHexadecimal,
127	"hexcolor":           IsHexcolor,
128	"rgbcolor":           IsRGBcolor,
129	"lowercase":          IsLowerCase,
130	"uppercase":          IsUpperCase,
131	"int":                IsInt,
132	"float":              IsFloat,
133	"null":               IsNull,
134	"notnull":            IsNotNull,
135	"uuid":               IsUUID,
136	"uuidv3":             IsUUIDv3,
137	"uuidv4":             IsUUIDv4,
138	"uuidv5":             IsUUIDv5,
139	"creditcard":         IsCreditCard,
140	"isbn10":             IsISBN10,
141	"isbn13":             IsISBN13,
142	"json":               IsJSON,
143	"multibyte":          IsMultibyte,
144	"ascii":              IsASCII,
145	"printableascii":     IsPrintableASCII,
146	"fullwidth":          IsFullWidth,
147	"halfwidth":          IsHalfWidth,
148	"variablewidth":      IsVariableWidth,
149	"base64":             IsBase64,
150	"datauri":            IsDataURI,
151	"ip":                 IsIP,
152	"port":               IsPort,
153	"ipv4":               IsIPv4,
154	"ipv6":               IsIPv6,
155	"dns":                IsDNSName,
156	"host":               IsHost,
157	"mac":                IsMAC,
158	"latitude":           IsLatitude,
159	"longitude":          IsLongitude,
160	"ssn":                IsSSN,
161	"semver":             IsSemver,
162	"rfc3339":            IsRFC3339,
163	"rfc3339WithoutZone": IsRFC3339WithoutZone,
164	"ISO3166Alpha2":      IsISO3166Alpha2,
165	"ISO3166Alpha3":      IsISO3166Alpha3,
166	"ISO4217":            IsISO4217,
167	"IMEI":               IsIMEI,
168	"ulid":               IsULID,
169}
170
171// ISO3166Entry stores country codes
172type ISO3166Entry struct {
173	EnglishShortName string
174	FrenchShortName  string
175	Alpha2Code       string
176	Alpha3Code       string
177	Numeric          string
178}
179
180//ISO3166List based on https://www.iso.org/obp/ui/#search/code/ Code Type "Officially Assigned Codes"
181var ISO3166List = []ISO3166Entry{
182	{"Afghanistan", "Afghanistan (l')", "AF", "AFG", "004"},
183	{"Albania", "Albanie (l')", "AL", "ALB", "008"},
184	{"Antarctica", "Antarctique (l')", "AQ", "ATA", "010"},
185	{"Algeria", "Algérie (l')", "DZ", "DZA", "012"},
186	{"American Samoa", "Samoa américaines (les)", "AS", "ASM", "016"},
187	{"Andorra", "Andorre (l')", "AD", "AND", "020"},
188	{"Angola", "Angola (l')", "AO", "AGO", "024"},
189	{"Antigua and Barbuda", "Antigua-et-Barbuda", "AG", "ATG", "028"},
190	{"Azerbaijan", "Azerbaïdjan (l')", "AZ", "AZE", "031"},
191	{"Argentina", "Argentine (l')", "AR", "ARG", "032"},
192	{"Australia", "Australie (l')", "AU", "AUS", "036"},
193	{"Austria", "Autriche (l')", "AT", "AUT", "040"},
194	{"Bahamas (the)", "Bahamas (les)", "BS", "BHS", "044"},
195	{"Bahrain", "Bahreïn", "BH", "BHR", "048"},
196	{"Bangladesh", "Bangladesh (le)", "BD", "BGD", "050"},
197	{"Armenia", "Arménie (l')", "AM", "ARM", "051"},
198	{"Barbados", "Barbade (la)", "BB", "BRB", "052"},
199	{"Belgium", "Belgique (la)", "BE", "BEL", "056"},
200	{"Bermuda", "Bermudes (les)", "BM", "BMU", "060"},
201	{"Bhutan", "Bhoutan (le)", "BT", "BTN", "064"},
202	{"Bolivia (Plurinational State of)", "Bolivie (État plurinational de)", "BO", "BOL", "068"},
203	{"Bosnia and Herzegovina", "Bosnie-Herzégovine (la)", "BA", "BIH", "070"},
204	{"Botswana", "Botswana (le)", "BW", "BWA", "072"},
205	{"Bouvet Island", "Bouvet (l'Île)", "BV", "BVT", "074"},
206	{"Brazil", "Brésil (le)", "BR", "BRA", "076"},
207	{"Belize", "Belize (le)", "BZ", "BLZ", "084"},
208	{"British Indian Ocean Territory (the)", "Indien (le Territoire britannique de l'océan)", "IO", "IOT", "086"},
209	{"Solomon Islands", "Salomon (Îles)", "SB", "SLB", "090"},
210	{"Virgin Islands (British)", "Vierges britanniques (les Îles)", "VG", "VGB", "092"},
211	{"Brunei Darussalam", "Brunéi Darussalam (le)", "BN", "BRN", "096"},
212	{"Bulgaria", "Bulgarie (la)", "BG", "BGR", "100"},
213	{"Myanmar", "Myanmar (le)", "MM", "MMR", "104"},
214	{"Burundi", "Burundi (le)", "BI", "BDI", "108"},
215	{"Belarus", "Bélarus (le)", "BY", "BLR", "112"},
216	{"Cambodia", "Cambodge (le)", "KH", "KHM", "116"},
217	{"Cameroon", "Cameroun (le)", "CM", "CMR", "120"},
218	{"Canada", "Canada (le)", "CA", "CAN", "124"},
219	{"Cabo Verde", "Cabo Verde", "CV", "CPV", "132"},
220	{"Cayman Islands (the)", "Caïmans (les Îles)", "KY", "CYM", "136"},
221	{"Central African Republic (the)", "République centrafricaine (la)", "CF", "CAF", "140"},
222	{"Sri Lanka", "Sri Lanka", "LK", "LKA", "144"},
223	{"Chad", "Tchad (le)", "TD", "TCD", "148"},
224	{"Chile", "Chili (le)", "CL", "CHL", "152"},
225	{"China", "Chine (la)", "CN", "CHN", "156"},
226	{"Taiwan (Province of China)", "Taïwan (Province de Chine)", "TW", "TWN", "158"},
227	{"Christmas Island", "Christmas (l'Île)", "CX", "CXR", "162"},
228	{"Cocos (Keeling) Islands (the)", "Cocos (les Îles)/ Keeling (les Îles)", "CC", "CCK", "166"},
229	{"Colombia", "Colombie (la)", "CO", "COL", "170"},
230	{"Comoros (the)", "Comores (les)", "KM", "COM", "174"},
231	{"Mayotte", "Mayotte", "YT", "MYT", "175"},
232	{"Congo (the)", "Congo (le)", "CG", "COG", "178"},
233	{"Congo (the Democratic Republic of the)", "Congo (la République démocratique du)", "CD", "COD", "180"},
234	{"Cook Islands (the)", "Cook (les Îles)", "CK", "COK", "184"},
235	{"Costa Rica", "Costa Rica (le)", "CR", "CRI", "188"},
236	{"Croatia", "Croatie (la)", "HR", "HRV", "191"},
237	{"Cuba", "Cuba", "CU", "CUB", "192"},
238	{"Cyprus", "Chypre", "CY", "CYP", "196"},
239	{"Czech Republic (the)", "tchèque (la République)", "CZ", "CZE", "203"},
240	{"Benin", "Bénin (le)", "BJ", "BEN", "204"},
241	{"Denmark", "Danemark (le)", "DK", "DNK", "208"},
242	{"Dominica", "Dominique (la)", "DM", "DMA", "212"},
243	{"Dominican Republic (the)", "dominicaine (la République)", "DO", "DOM", "214"},
244	{"Ecuador", "Équateur (l')", "EC", "ECU", "218"},
245	{"El Salvador", "El Salvador", "SV", "SLV", "222"},
246	{"Equatorial Guinea", "Guinée équatoriale (la)", "GQ", "GNQ", "226"},
247	{"Ethiopia", "Éthiopie (l')", "ET", "ETH", "231"},
248	{"Eritrea", "Érythrée (l')", "ER", "ERI", "232"},
249	{"Estonia", "Estonie (l')", "EE", "EST", "233"},
250	{"Faroe Islands (the)", "Féroé (les Îles)", "FO", "FRO", "234"},
251	{"Falkland Islands (the) [Malvinas]", "Falkland (les Îles)/Malouines (les Îles)", "FK", "FLK", "238"},
252	{"South Georgia and the South Sandwich Islands", "Géorgie du Sud-et-les Îles Sandwich du Sud (la)", "GS", "SGS", "239"},
253	{"Fiji", "Fidji (les)", "FJ", "FJI", "242"},
254	{"Finland", "Finlande (la)", "FI", "FIN", "246"},
255	{"Åland Islands", "Åland(les Îles)", "AX", "ALA", "248"},
256	{"France", "France (la)", "FR", "FRA", "250"},
257	{"French Guiana", "Guyane française (la )", "GF", "GUF", "254"},
258	{"French Polynesia", "Polynésie française (la)", "PF", "PYF", "258"},
259	{"French Southern Territories (the)", "Terres australes françaises (les)", "TF", "ATF", "260"},
260	{"Djibouti", "Djibouti", "DJ", "DJI", "262"},
261	{"Gabon", "Gabon (le)", "GA", "GAB", "266"},
262	{"Georgia", "Géorgie (la)", "GE", "GEO", "268"},
263	{"Gambia (the)", "Gambie (la)", "GM", "GMB", "270"},
264	{"Palestine, State of", "Palestine, État de", "PS", "PSE", "275"},
265	{"Germany", "Allemagne (l')", "DE", "DEU", "276"},
266	{"Ghana", "Ghana (le)", "GH", "GHA", "288"},
267	{"Gibraltar", "Gibraltar", "GI", "GIB", "292"},
268	{"Kiribati", "Kiribati", "KI", "KIR", "296"},
269	{"Greece", "Grèce (la)", "GR", "GRC", "300"},
270	{"Greenland", "Groenland (le)", "GL", "GRL", "304"},
271	{"Grenada", "Grenade (la)", "GD", "GRD", "308"},
272	{"Guadeloupe", "Guadeloupe (la)", "GP", "GLP", "312"},
273	{"Guam", "Guam", "GU", "GUM", "316"},
274	{"Guatemala", "Guatemala (le)", "GT", "GTM", "320"},
275	{"Guinea", "Guinée (la)", "GN", "GIN", "324"},
276	{"Guyana", "Guyana (le)", "GY", "GUY", "328"},
277	{"Haiti", "Haïti", "HT", "HTI", "332"},
278	{"Heard Island and McDonald Islands", "Heard-et-Îles MacDonald (l'Île)", "HM", "HMD", "334"},
279	{"Holy See (the)", "Saint-Siège (le)", "VA", "VAT", "336"},
280	{"Honduras", "Honduras (le)", "HN", "HND", "340"},
281	{"Hong Kong", "Hong Kong", "HK", "HKG", "344"},
282	{"Hungary", "Hongrie (la)", "HU", "HUN", "348"},
283	{"Iceland", "Islande (l')", "IS", "ISL", "352"},
284	{"India", "Inde (l')", "IN", "IND", "356"},
285	{"Indonesia", "Indonésie (l')", "ID", "IDN", "360"},
286	{"Iran (Islamic Republic of)", "Iran (République Islamique d')", "IR", "IRN", "364"},
287	{"Iraq", "Iraq (l')", "IQ", "IRQ", "368"},
288	{"Ireland", "Irlande (l')", "IE", "IRL", "372"},
289	{"Israel", "Israël", "IL", "ISR", "376"},
290	{"Italy", "Italie (l')", "IT", "ITA", "380"},
291	{"Côte d'Ivoire", "Côte d'Ivoire (la)", "CI", "CIV", "384"},
292	{"Jamaica", "Jamaïque (la)", "JM", "JAM", "388"},
293	{"Japan", "Japon (le)", "JP", "JPN", "392"},
294	{"Kazakhstan", "Kazakhstan (le)", "KZ", "KAZ", "398"},
295	{"Jordan", "Jordanie (la)", "JO", "JOR", "400"},
296	{"Kenya", "Kenya (le)", "KE", "KEN", "404"},
297	{"Korea (the Democratic People's Republic of)", "Corée (la République populaire démocratique de)", "KP", "PRK", "408"},
298	{"Korea (the Republic of)", "Corée (la République de)", "KR", "KOR", "410"},
299	{"Kuwait", "Koweït (le)", "KW", "KWT", "414"},
300	{"Kyrgyzstan", "Kirghizistan (le)", "KG", "KGZ", "417"},
301	{"Lao People's Democratic Republic (the)", "Lao, République démocratique populaire", "LA", "LAO", "418"},
302	{"Lebanon", "Liban (le)", "LB", "LBN", "422"},
303	{"Lesotho", "Lesotho (le)", "LS", "LSO", "426"},
304	{"Latvia", "Lettonie (la)", "LV", "LVA", "428"},
305	{"Liberia", "Libéria (le)", "LR", "LBR", "430"},
306	{"Libya", "Libye (la)", "LY", "LBY", "434"},
307	{"Liechtenstein", "Liechtenstein (le)", "LI", "LIE", "438"},
308	{"Lithuania", "Lituanie (la)", "LT", "LTU", "440"},
309	{"Luxembourg", "Luxembourg (le)", "LU", "LUX", "442"},
310	{"Macao", "Macao", "MO", "MAC", "446"},
311	{"Madagascar", "Madagascar", "MG", "MDG", "450"},
312	{"Malawi", "Malawi (le)", "MW", "MWI", "454"},
313	{"Malaysia", "Malaisie (la)", "MY", "MYS", "458"},
314	{"Maldives", "Maldives (les)", "MV", "MDV", "462"},
315	{"Mali", "Mali (le)", "ML", "MLI", "466"},
316	{"Malta", "Malte", "MT", "MLT", "470"},
317	{"Martinique", "Martinique (la)", "MQ", "MTQ", "474"},
318	{"Mauritania", "Mauritanie (la)", "MR", "MRT", "478"},
319	{"Mauritius", "Maurice", "MU", "MUS", "480"},
320	{"Mexico", "Mexique (le)", "MX", "MEX", "484"},
321	{"Monaco", "Monaco", "MC", "MCO", "492"},
322	{"Mongolia", "Mongolie (la)", "MN", "MNG", "496"},
323	{"Moldova (the Republic of)", "Moldova , République de", "MD", "MDA", "498"},
324	{"Montenegro", "Monténégro (le)", "ME", "MNE", "499"},
325	{"Montserrat", "Montserrat", "MS", "MSR", "500"},
326	{"Morocco", "Maroc (le)", "MA", "MAR", "504"},
327	{"Mozambique", "Mozambique (le)", "MZ", "MOZ", "508"},
328	{"Oman", "Oman", "OM", "OMN", "512"},
329	{"Namibia", "Namibie (la)", "NA", "NAM", "516"},
330	{"Nauru", "Nauru", "NR", "NRU", "520"},
331	{"Nepal", "Népal (le)", "NP", "NPL", "524"},
332	{"Netherlands (the)", "Pays-Bas (les)", "NL", "NLD", "528"},
333	{"Curaçao", "Curaçao", "CW", "CUW", "531"},
334	{"Aruba", "Aruba", "AW", "ABW", "533"},
335	{"Sint Maarten (Dutch part)", "Saint-Martin (partie néerlandaise)", "SX", "SXM", "534"},
336	{"Bonaire, Sint Eustatius and Saba", "Bonaire, Saint-Eustache et Saba", "BQ", "BES", "535"},
337	{"New Caledonia", "Nouvelle-Calédonie (la)", "NC", "NCL", "540"},
338	{"Vanuatu", "Vanuatu (le)", "VU", "VUT", "548"},
339	{"New Zealand", "Nouvelle-Zélande (la)", "NZ", "NZL", "554"},
340	{"Nicaragua", "Nicaragua (le)", "NI", "NIC", "558"},
341	{"Niger (the)", "Niger (le)", "NE", "NER", "562"},
342	{"Nigeria", "Nigéria (le)", "NG", "NGA", "566"},
343	{"Niue", "Niue", "NU", "NIU", "570"},
344	{"Norfolk Island", "Norfolk (l'Île)", "NF", "NFK", "574"},
345	{"Norway", "Norvège (la)", "NO", "NOR", "578"},
346	{"Northern Mariana Islands (the)", "Mariannes du Nord (les Îles)", "MP", "MNP", "580"},
347	{"United States Minor Outlying Islands (the)", "Îles mineures éloignées des États-Unis (les)", "UM", "UMI", "581"},
348	{"Micronesia (Federated States of)", "Micronésie (États fédérés de)", "FM", "FSM", "583"},
349	{"Marshall Islands (the)", "Marshall (Îles)", "MH", "MHL", "584"},
350	{"Palau", "Palaos (les)", "PW", "PLW", "585"},
351	{"Pakistan", "Pakistan (le)", "PK", "PAK", "586"},
352	{"Panama", "Panama (le)", "PA", "PAN", "591"},
353	{"Papua New Guinea", "Papouasie-Nouvelle-Guinée (la)", "PG", "PNG", "598"},
354	{"Paraguay", "Paraguay (le)", "PY", "PRY", "600"},
355	{"Peru", "Pérou (le)", "PE", "PER", "604"},
356	{"Philippines (the)", "Philippines (les)", "PH", "PHL", "608"},
357	{"Pitcairn", "Pitcairn", "PN", "PCN", "612"},
358	{"Poland", "Pologne (la)", "PL", "POL", "616"},
359	{"Portugal", "Portugal (le)", "PT", "PRT", "620"},
360	{"Guinea-Bissau", "Guinée-Bissau (la)", "GW", "GNB", "624"},
361	{"Timor-Leste", "Timor-Leste (le)", "TL", "TLS", "626"},
362	{"Puerto Rico", "Porto Rico", "PR", "PRI", "630"},
363	{"Qatar", "Qatar (le)", "QA", "QAT", "634"},
364	{"Réunion", "Réunion (La)", "RE", "REU", "638"},
365	{"Romania", "Roumanie (la)", "RO", "ROU", "642"},
366	{"Russian Federation (the)", "Russie (la Fédération de)", "RU", "RUS", "643"},
367	{"Rwanda", "Rwanda (le)", "RW", "RWA", "646"},
368	{"Saint Barthélemy", "Saint-Barthélemy", "BL", "BLM", "652"},
369	{"Saint Helena, Ascension and Tristan da Cunha", "Sainte-Hélène, Ascension et Tristan da Cunha", "SH", "SHN", "654"},
370	{"Saint Kitts and Nevis", "Saint-Kitts-et-Nevis", "KN", "KNA", "659"},
371	{"Anguilla", "Anguilla", "AI", "AIA", "660"},
372	{"Saint Lucia", "Sainte-Lucie", "LC", "LCA", "662"},
373	{"Saint Martin (French part)", "Saint-Martin (partie française)", "MF", "MAF", "663"},
374	{"Saint Pierre and Miquelon", "Saint-Pierre-et-Miquelon", "PM", "SPM", "666"},
375	{"Saint Vincent and the Grenadines", "Saint-Vincent-et-les Grenadines", "VC", "VCT", "670"},
376	{"San Marino", "Saint-Marin", "SM", "SMR", "674"},
377	{"Sao Tome and Principe", "Sao Tomé-et-Principe", "ST", "STP", "678"},
378	{"Saudi Arabia", "Arabie saoudite (l')", "SA", "SAU", "682"},
379	{"Senegal", "Sénégal (le)", "SN", "SEN", "686"},
380	{"Serbia", "Serbie (la)", "RS", "SRB", "688"},
381	{"Seychelles", "Seychelles (les)", "SC", "SYC", "690"},
382	{"Sierra Leone", "Sierra Leone (la)", "SL", "SLE", "694"},
383	{"Singapore", "Singapour", "SG", "SGP", "702"},
384	{"Slovakia", "Slovaquie (la)", "SK", "SVK", "703"},
385	{"Viet Nam", "Viet Nam (le)", "VN", "VNM", "704"},
386	{"Slovenia", "Slovénie (la)", "SI", "SVN", "705"},
387	{"Somalia", "Somalie (la)", "SO", "SOM", "706"},
388	{"South Africa", "Afrique du Sud (l')", "ZA", "ZAF", "710"},
389	{"Zimbabwe", "Zimbabwe (le)", "ZW", "ZWE", "716"},
390	{"Spain", "Espagne (l')", "ES", "ESP", "724"},
391	{"South Sudan", "Soudan du Sud (le)", "SS", "SSD", "728"},
392	{"Sudan (the)", "Soudan (le)", "SD", "SDN", "729"},
393	{"Western Sahara*", "Sahara occidental (le)*", "EH", "ESH", "732"},
394	{"Suriname", "Suriname (le)", "SR", "SUR", "740"},
395	{"Svalbard and Jan Mayen", "Svalbard et l'Île Jan Mayen (le)", "SJ", "SJM", "744"},
396	{"Swaziland", "Swaziland (le)", "SZ", "SWZ", "748"},
397	{"Sweden", "Suède (la)", "SE", "SWE", "752"},
398	{"Switzerland", "Suisse (la)", "CH", "CHE", "756"},
399	{"Syrian Arab Republic", "République arabe syrienne (la)", "SY", "SYR", "760"},
400	{"Tajikistan", "Tadjikistan (le)", "TJ", "TJK", "762"},
401	{"Thailand", "Thaïlande (la)", "TH", "THA", "764"},
402	{"Togo", "Togo (le)", "TG", "TGO", "768"},
403	{"Tokelau", "Tokelau (les)", "TK", "TKL", "772"},
404	{"Tonga", "Tonga (les)", "TO", "TON", "776"},
405	{"Trinidad and Tobago", "Trinité-et-Tobago (la)", "TT", "TTO", "780"},
406	{"United Arab Emirates (the)", "Émirats arabes unis (les)", "AE", "ARE", "784"},
407	{"Tunisia", "Tunisie (la)", "TN", "TUN", "788"},
408	{"Turkey", "Turquie (la)", "TR", "TUR", "792"},
409	{"Turkmenistan", "Turkménistan (le)", "TM", "TKM", "795"},
410	{"Turks and Caicos Islands (the)", "Turks-et-Caïcos (les Îles)", "TC", "TCA", "796"},
411	{"Tuvalu", "Tuvalu (les)", "TV", "TUV", "798"},
412	{"Uganda", "Ouganda (l')", "UG", "UGA", "800"},
413	{"Ukraine", "Ukraine (l')", "UA", "UKR", "804"},
414	{"Macedonia (the former Yugoslav Republic of)", "Macédoine (l'ex‑République yougoslave de)", "MK", "MKD", "807"},
415	{"Egypt", "Égypte (l')", "EG", "EGY", "818"},
416	{"United Kingdom of Great Britain and Northern Ireland (the)", "Royaume-Uni de Grande-Bretagne et d'Irlande du Nord (le)", "GB", "GBR", "826"},
417	{"Guernsey", "Guernesey", "GG", "GGY", "831"},
418	{"Jersey", "Jersey", "JE", "JEY", "832"},
419	{"Isle of Man", "Île de Man", "IM", "IMN", "833"},
420	{"Tanzania, United Republic of", "Tanzanie, République-Unie de", "TZ", "TZA", "834"},
421	{"United States of America (the)", "États-Unis d'Amérique (les)", "US", "USA", "840"},
422	{"Virgin Islands (U.S.)", "Vierges des États-Unis (les Îles)", "VI", "VIR", "850"},
423	{"Burkina Faso", "Burkina Faso (le)", "BF", "BFA", "854"},
424	{"Uruguay", "Uruguay (l')", "UY", "URY", "858"},
425	{"Uzbekistan", "Ouzbékistan (l')", "UZ", "UZB", "860"},
426	{"Venezuela (Bolivarian Republic of)", "Venezuela (République bolivarienne du)", "VE", "VEN", "862"},
427	{"Wallis and Futuna", "Wallis-et-Futuna", "WF", "WLF", "876"},
428	{"Samoa", "Samoa (le)", "WS", "WSM", "882"},
429	{"Yemen", "Yémen (le)", "YE", "YEM", "887"},
430	{"Zambia", "Zambie (la)", "ZM", "ZMB", "894"},
431}
432
433// ISO4217List is the list of ISO currency codes
434var ISO4217List = []string{
435	"AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN",
436	"BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BOV", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD",
437	"CAD", "CDF", "CHE", "CHF", "CHW", "CLF", "CLP", "CNY", "COP", "COU", "CRC", "CUC", "CUP", "CVE", "CZK",
438	"DJF", "DKK", "DOP", "DZD",
439	"EGP", "ERN", "ETB", "EUR",
440	"FJD", "FKP",
441	"GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD",
442	"HKD", "HNL", "HRK", "HTG", "HUF",
443	"IDR", "ILS", "INR", "IQD", "IRR", "ISK",
444	"JMD", "JOD", "JPY",
445	"KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT",
446	"LAK", "LBP", "LKR", "LRD", "LSL", "LYD",
447	"MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MUR", "MVR", "MWK", "MXN", "MXV", "MYR", "MZN",
448	"NAD", "NGN", "NIO", "NOK", "NPR", "NZD",
449	"OMR",
450	"PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG",
451	"QAR",
452	"RON", "RSD", "RUB", "RWF",
453	"SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STD", "STN", "SVC", "SYP", "SZL",
454	"THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS",
455	"UAH", "UGX", "USD", "USN", "UYI", "UYU", "UYW", "UZS",
456	"VEF", "VES", "VND", "VUV",
457	"WST",
458	"XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XOF", "XPD", "XPF", "XPT", "XSU", "XTS", "XUA", "XXX",
459	"YER",
460	"ZAR", "ZMW", "ZWL",
461}
462
463// ISO693Entry stores ISO language codes
464type ISO693Entry struct {
465	Alpha3bCode string
466	Alpha2Code  string
467	English     string
468}
469
470//ISO693List based on http://data.okfn.org/data/core/language-codes/r/language-codes-3b2.json
471var ISO693List = []ISO693Entry{
472	{Alpha3bCode: "aar", Alpha2Code: "aa", English: "Afar"},
473	{Alpha3bCode: "abk", Alpha2Code: "ab", English: "Abkhazian"},
474	{Alpha3bCode: "afr", Alpha2Code: "af", English: "Afrikaans"},
475	{Alpha3bCode: "aka", Alpha2Code: "ak", English: "Akan"},
476	{Alpha3bCode: "alb", Alpha2Code: "sq", English: "Albanian"},
477	{Alpha3bCode: "amh", Alpha2Code: "am", English: "Amharic"},
478	{Alpha3bCode: "ara", Alpha2Code: "ar", English: "Arabic"},
479	{Alpha3bCode: "arg", Alpha2Code: "an", English: "Aragonese"},
480	{Alpha3bCode: "arm", Alpha2Code: "hy", English: "Armenian"},
481	{Alpha3bCode: "asm", Alpha2Code: "as", English: "Assamese"},
482	{Alpha3bCode: "ava", Alpha2Code: "av", English: "Avaric"},
483	{Alpha3bCode: "ave", Alpha2Code: "ae", English: "Avestan"},
484	{Alpha3bCode: "aym", Alpha2Code: "ay", English: "Aymara"},
485	{Alpha3bCode: "aze", Alpha2Code: "az", English: "Azerbaijani"},
486	{Alpha3bCode: "bak", Alpha2Code: "ba", English: "Bashkir"},
487	{Alpha3bCode: "bam", Alpha2Code: "bm", English: "Bambara"},
488	{Alpha3bCode: "baq", Alpha2Code: "eu", English: "Basque"},
489	{Alpha3bCode: "bel", Alpha2Code: "be", English: "Belarusian"},
490	{Alpha3bCode: "ben", Alpha2Code: "bn", English: "Bengali"},
491	{Alpha3bCode: "bih", Alpha2Code: "bh", English: "Bihari languages"},
492	{Alpha3bCode: "bis", Alpha2Code: "bi", English: "Bislama"},
493	{Alpha3bCode: "bos", Alpha2Code: "bs", English: "Bosnian"},
494	{Alpha3bCode: "bre", Alpha2Code: "br", English: "Breton"},
495	{Alpha3bCode: "bul", Alpha2Code: "bg", English: "Bulgarian"},
496	{Alpha3bCode: "bur", Alpha2Code: "my", English: "Burmese"},
497	{Alpha3bCode: "cat", Alpha2Code: "ca", English: "Catalan; Valencian"},
498	{Alpha3bCode: "cha", Alpha2Code: "ch", English: "Chamorro"},
499	{Alpha3bCode: "che", Alpha2Code: "ce", English: "Chechen"},
500	{Alpha3bCode: "chi", Alpha2Code: "zh", English: "Chinese"},
501	{Alpha3bCode: "chu", Alpha2Code: "cu", English: "Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic"},
502	{Alpha3bCode: "chv", Alpha2Code: "cv", English: "Chuvash"},
503	{Alpha3bCode: "cor", Alpha2Code: "kw", English: "Cornish"},
504	{Alpha3bCode: "cos", Alpha2Code: "co", English: "Corsican"},
505	{Alpha3bCode: "cre", Alpha2Code: "cr", English: "Cree"},
506	{Alpha3bCode: "cze", Alpha2Code: "cs", English: "Czech"},
507	{Alpha3bCode: "dan", Alpha2Code: "da", English: "Danish"},
508	{Alpha3bCode: "div", Alpha2Code: "dv", English: "Divehi; Dhivehi; Maldivian"},
509	{Alpha3bCode: "dut", Alpha2Code: "nl", English: "Dutch; Flemish"},
510	{Alpha3bCode: "dzo", Alpha2Code: "dz", English: "Dzongkha"},
511	{Alpha3bCode: "eng", Alpha2Code: "en", English: "English"},
512	{Alpha3bCode: "epo", Alpha2Code: "eo", English: "Esperanto"},
513	{Alpha3bCode: "est", Alpha2Code: "et", English: "Estonian"},
514	{Alpha3bCode: "ewe", Alpha2Code: "ee", English: "Ewe"},
515	{Alpha3bCode: "fao", Alpha2Code: "fo", English: "Faroese"},
516	{Alpha3bCode: "fij", Alpha2Code: "fj", English: "Fijian"},
517	{Alpha3bCode: "fin", Alpha2Code: "fi", English: "Finnish"},
518	{Alpha3bCode: "fre", Alpha2Code: "fr", English: "French"},
519	{Alpha3bCode: "fry", Alpha2Code: "fy", English: "Western Frisian"},
520	{Alpha3bCode: "ful", Alpha2Code: "ff", English: "Fulah"},
521	{Alpha3bCode: "geo", Alpha2Code: "ka", English: "Georgian"},
522	{Alpha3bCode: "ger", Alpha2Code: "de", English: "German"},
523	{Alpha3bCode: "gla", Alpha2Code: "gd", English: "Gaelic; Scottish Gaelic"},
524	{Alpha3bCode: "gle", Alpha2Code: "ga", English: "Irish"},
525	{Alpha3bCode: "glg", Alpha2Code: "gl", English: "Galician"},
526	{Alpha3bCode: "glv", Alpha2Code: "gv", English: "Manx"},
527	{Alpha3bCode: "gre", Alpha2Code: "el", English: "Greek, Modern (1453-)"},
528	{Alpha3bCode: "grn", Alpha2Code: "gn", English: "Guarani"},
529	{Alpha3bCode: "guj", Alpha2Code: "gu", English: "Gujarati"},
530	{Alpha3bCode: "hat", Alpha2Code: "ht", English: "Haitian; Haitian Creole"},
531	{Alpha3bCode: "hau", Alpha2Code: "ha", English: "Hausa"},
532	{Alpha3bCode: "heb", Alpha2Code: "he", English: "Hebrew"},
533	{Alpha3bCode: "her", Alpha2Code: "hz", English: "Herero"},
534	{Alpha3bCode: "hin", Alpha2Code: "hi", English: "Hindi"},
535	{Alpha3bCode: "hmo", Alpha2Code: "ho", English: "Hiri Motu"},
536	{Alpha3bCode: "hrv", Alpha2Code: "hr", English: "Croatian"},
537	{Alpha3bCode: "hun", Alpha2Code: "hu", English: "Hungarian"},
538	{Alpha3bCode: "ibo", Alpha2Code: "ig", English: "Igbo"},
539	{Alpha3bCode: "ice", Alpha2Code: "is", English: "Icelandic"},
540	{Alpha3bCode: "ido", Alpha2Code: "io", English: "Ido"},
541	{Alpha3bCode: "iii", Alpha2Code: "ii", English: "Sichuan Yi; Nuosu"},
542	{Alpha3bCode: "iku", Alpha2Code: "iu", English: "Inuktitut"},
543	{Alpha3bCode: "ile", Alpha2Code: "ie", English: "Interlingue; Occidental"},
544	{Alpha3bCode: "ina", Alpha2Code: "ia", English: "Interlingua (International Auxiliary Language Association)"},
545	{Alpha3bCode: "ind", Alpha2Code: "id", English: "Indonesian"},
546	{Alpha3bCode: "ipk", Alpha2Code: "ik", English: "Inupiaq"},
547	{Alpha3bCode: "ita", Alpha2Code: "it", English: "Italian"},
548	{Alpha3bCode: "jav", Alpha2Code: "jv", English: "Javanese"},
549	{Alpha3bCode: "jpn", Alpha2Code: "ja", English: "Japanese"},
550	{Alpha3bCode: "kal", Alpha2Code: "kl", English: "Kalaallisut; Greenlandic"},
551	{Alpha3bCode: "kan", Alpha2Code: "kn", English: "Kannada"},
552	{Alpha3bCode: "kas", Alpha2Code: "ks", English: "Kashmiri"},
553	{Alpha3bCode: "kau", Alpha2Code: "kr", English: "Kanuri"},
554	{Alpha3bCode: "kaz", Alpha2Code: "kk", English: "Kazakh"},
555	{Alpha3bCode: "khm", Alpha2Code: "km", English: "Central Khmer"},
556	{Alpha3bCode: "kik", Alpha2Code: "ki", English: "Kikuyu; Gikuyu"},
557	{Alpha3bCode: "kin", Alpha2Code: "rw", English: "Kinyarwanda"},
558	{Alpha3bCode: "kir", Alpha2Code: "ky", English: "Kirghiz; Kyrgyz"},
559	{Alpha3bCode: "kom", Alpha2Code: "kv", English: "Komi"},
560	{Alpha3bCode: "kon", Alpha2Code: "kg", English: "Kongo"},
561	{Alpha3bCode: "kor", Alpha2Code: "ko", English: "Korean"},
562	{Alpha3bCode: "kua", Alpha2Code: "kj", English: "Kuanyama; Kwanyama"},
563	{Alpha3bCode: "kur", Alpha2Code: "ku", English: "Kurdish"},
564	{Alpha3bCode: "lao", Alpha2Code: "lo", English: "Lao"},
565	{Alpha3bCode: "lat", Alpha2Code: "la", English: "Latin"},
566	{Alpha3bCode: "lav", Alpha2Code: "lv", English: "Latvian"},
567	{Alpha3bCode: "lim", Alpha2Code: "li", English: "Limburgan; Limburger; Limburgish"},
568	{Alpha3bCode: "lin", Alpha2Code: "ln", English: "Lingala"},
569	{Alpha3bCode: "lit", Alpha2Code: "lt", English: "Lithuanian"},
570	{Alpha3bCode: "ltz", Alpha2Code: "lb", English: "Luxembourgish; Letzeburgesch"},
571	{Alpha3bCode: "lub", Alpha2Code: "lu", English: "Luba-Katanga"},
572	{Alpha3bCode: "lug", Alpha2Code: "lg", English: "Ganda"},
573	{Alpha3bCode: "mac", Alpha2Code: "mk", English: "Macedonian"},
574	{Alpha3bCode: "mah", Alpha2Code: "mh", English: "Marshallese"},
575	{Alpha3bCode: "mal", Alpha2Code: "ml", English: "Malayalam"},
576	{Alpha3bCode: "mao", Alpha2Code: "mi", English: "Maori"},
577	{Alpha3bCode: "mar", Alpha2Code: "mr", English: "Marathi"},
578	{Alpha3bCode: "may", Alpha2Code: "ms", English: "Malay"},
579	{Alpha3bCode: "mlg", Alpha2Code: "mg", English: "Malagasy"},
580	{Alpha3bCode: "mlt", Alpha2Code: "mt", English: "Maltese"},
581	{Alpha3bCode: "mon", Alpha2Code: "mn", English: "Mongolian"},
582	{Alpha3bCode: "nau", Alpha2Code: "na", English: "Nauru"},
583	{Alpha3bCode: "nav", Alpha2Code: "nv", English: "Navajo; Navaho"},
584	{Alpha3bCode: "nbl", Alpha2Code: "nr", English: "Ndebele, South; South Ndebele"},
585	{Alpha3bCode: "nde", Alpha2Code: "nd", English: "Ndebele, North; North Ndebele"},
586	{Alpha3bCode: "ndo", Alpha2Code: "ng", English: "Ndonga"},
587	{Alpha3bCode: "nep", Alpha2Code: "ne", English: "Nepali"},
588	{Alpha3bCode: "nno", Alpha2Code: "nn", English: "Norwegian Nynorsk; Nynorsk, Norwegian"},
589	{Alpha3bCode: "nob", Alpha2Code: "nb", English: "Bokmål, Norwegian; Norwegian Bokmål"},
590	{Alpha3bCode: "nor", Alpha2Code: "no", English: "Norwegian"},
591	{Alpha3bCode: "nya", Alpha2Code: "ny", English: "Chichewa; Chewa; Nyanja"},
592	{Alpha3bCode: "oci", Alpha2Code: "oc", English: "Occitan (post 1500); Provençal"},
593	{Alpha3bCode: "oji", Alpha2Code: "oj", English: "Ojibwa"},
594	{Alpha3bCode: "ori", Alpha2Code: "or", English: "Oriya"},
595	{Alpha3bCode: "orm", Alpha2Code: "om", English: "Oromo"},
596	{Alpha3bCode: "oss", Alpha2Code: "os", English: "Ossetian; Ossetic"},
597	{Alpha3bCode: "pan", Alpha2Code: "pa", English: "Panjabi; Punjabi"},
598	{Alpha3bCode: "per", Alpha2Code: "fa", English: "Persian"},
599	{Alpha3bCode: "pli", Alpha2Code: "pi", English: "Pali"},
600	{Alpha3bCode: "pol", Alpha2Code: "pl", English: "Polish"},
601	{Alpha3bCode: "por", Alpha2Code: "pt", English: "Portuguese"},
602	{Alpha3bCode: "pus", Alpha2Code: "ps", English: "Pushto; Pashto"},
603	{Alpha3bCode: "que", Alpha2Code: "qu", English: "Quechua"},
604	{Alpha3bCode: "roh", Alpha2Code: "rm", English: "Romansh"},
605	{Alpha3bCode: "rum", Alpha2Code: "ro", English: "Romanian; Moldavian; Moldovan"},
606	{Alpha3bCode: "run", Alpha2Code: "rn", English: "Rundi"},
607	{Alpha3bCode: "rus", Alpha2Code: "ru", English: "Russian"},
608	{Alpha3bCode: "sag", Alpha2Code: "sg", English: "Sango"},
609	{Alpha3bCode: "san", Alpha2Code: "sa", English: "Sanskrit"},
610	{Alpha3bCode: "sin", Alpha2Code: "si", English: "Sinhala; Sinhalese"},
611	{Alpha3bCode: "slo", Alpha2Code: "sk", English: "Slovak"},
612	{Alpha3bCode: "slv", Alpha2Code: "sl", English: "Slovenian"},
613	{Alpha3bCode: "sme", Alpha2Code: "se", English: "Northern Sami"},
614	{Alpha3bCode: "smo", Alpha2Code: "sm", English: "Samoan"},
615	{Alpha3bCode: "sna", Alpha2Code: "sn", English: "Shona"},
616	{Alpha3bCode: "snd", Alpha2Code: "sd", English: "Sindhi"},
617	{Alpha3bCode: "som", Alpha2Code: "so", English: "Somali"},
618	{Alpha3bCode: "sot", Alpha2Code: "st", English: "Sotho, Southern"},
619	{Alpha3bCode: "spa", Alpha2Code: "es", English: "Spanish; Castilian"},
620	{Alpha3bCode: "srd", Alpha2Code: "sc", English: "Sardinian"},
621	{Alpha3bCode: "srp", Alpha2Code: "sr", English: "Serbian"},
622	{Alpha3bCode: "ssw", Alpha2Code: "ss", English: "Swati"},
623	{Alpha3bCode: "sun", Alpha2Code: "su", English: "Sundanese"},
624	{Alpha3bCode: "swa", Alpha2Code: "sw", English: "Swahili"},
625	{Alpha3bCode: "swe", Alpha2Code: "sv", English: "Swedish"},
626	{Alpha3bCode: "tah", Alpha2Code: "ty", English: "Tahitian"},
627	{Alpha3bCode: "tam", Alpha2Code: "ta", English: "Tamil"},
628	{Alpha3bCode: "tat", Alpha2Code: "tt", English: "Tatar"},
629	{Alpha3bCode: "tel", Alpha2Code: "te", English: "Telugu"},
630	{Alpha3bCode: "tgk", Alpha2Code: "tg", English: "Tajik"},
631	{Alpha3bCode: "tgl", Alpha2Code: "tl", English: "Tagalog"},
632	{Alpha3bCode: "tha", Alpha2Code: "th", English: "Thai"},
633	{Alpha3bCode: "tib", Alpha2Code: "bo", English: "Tibetan"},
634	{Alpha3bCode: "tir", Alpha2Code: "ti", English: "Tigrinya"},
635	{Alpha3bCode: "ton", Alpha2Code: "to", English: "Tonga (Tonga Islands)"},
636	{Alpha3bCode: "tsn", Alpha2Code: "tn", English: "Tswana"},
637	{Alpha3bCode: "tso", Alpha2Code: "ts", English: "Tsonga"},
638	{Alpha3bCode: "tuk", Alpha2Code: "tk", English: "Turkmen"},
639	{Alpha3bCode: "tur", Alpha2Code: "tr", English: "Turkish"},
640	{Alpha3bCode: "twi", Alpha2Code: "tw", English: "Twi"},
641	{Alpha3bCode: "uig", Alpha2Code: "ug", English: "Uighur; Uyghur"},
642	{Alpha3bCode: "ukr", Alpha2Code: "uk", English: "Ukrainian"},
643	{Alpha3bCode: "urd", Alpha2Code: "ur", English: "Urdu"},
644	{Alpha3bCode: "uzb", Alpha2Code: "uz", English: "Uzbek"},
645	{Alpha3bCode: "ven", Alpha2Code: "ve", English: "Venda"},
646	{Alpha3bCode: "vie", Alpha2Code: "vi", English: "Vietnamese"},
647	{Alpha3bCode: "vol", Alpha2Code: "vo", English: "Volapük"},
648	{Alpha3bCode: "wel", Alpha2Code: "cy", English: "Welsh"},
649	{Alpha3bCode: "wln", Alpha2Code: "wa", English: "Walloon"},
650	{Alpha3bCode: "wol", Alpha2Code: "wo", English: "Wolof"},
651	{Alpha3bCode: "xho", Alpha2Code: "xh", English: "Xhosa"},
652	{Alpha3bCode: "yid", Alpha2Code: "yi", English: "Yiddish"},
653	{Alpha3bCode: "yor", Alpha2Code: "yo", English: "Yoruba"},
654	{Alpha3bCode: "zha", Alpha2Code: "za", English: "Zhuang; Chuang"},
655	{Alpha3bCode: "zul", Alpha2Code: "zu", English: "Zulu"},
656}
657