Skip to content

Instantly share code, notes, and snippets.

@slax0rr
Created April 23, 2018 12:49
Show Gist options
  • Save slax0rr/8115bb837555fa4a62b9a70af1a62092 to your computer and use it in GitHub Desktop.
Save slax0rr/8115bb837555fa4a62b9a70af1a62092 to your computer and use it in GitHub Desktop.
package countries
//go:generate go run gen.go
type Country struct {
ISO2 string `json:"iso2"`
ISO3 string `json:"iso3"`
Name string `json:"name"`
Continent string `json:"continent"`
}
type CountryList map[string]Country
func GetCountries() map[string]Country {
return countries
}
func GetCountryByISO2(iso2 string) Country {
return countries[iso2]
}
{"AW":{"iso2":"AW","iso3":"ABW","name":"Aruba","continent":"Americas"},"AF":{"iso2":"AF","iso3":"AFG","name":"Islamic Republic of Afghanistan","continent":"Asia"},"AO":{"iso2":"AO","iso3":"AGO","name":"Republic of Angola","continent":"Africa"},"AI":{"iso2":"AI","iso3":"AIA","name":"Anguilla","continent":"Americas"},"AX":{"iso2":"AX","iso3":"ALA","name":"\u00c5land Islands","continent":"Europe"},"AL":{"iso2":"AL","iso3":"ALB","name":"Republic of Albania","continent":"Europe"},"AD":{"iso2":"AD","iso3":"AND","name":"Principality of Andorra","continent":"Europe"},"AE":{"iso2":"AE","iso3":"ARE","name":"United Arab Emirates","continent":"Asia"},"AR":{"iso2":"AR","iso3":"ARG","name":"Argentine Republic","continent":"Americas"},"AM":{"iso2":"AM","iso3":"ARM","name":"Republic of Armenia","continent":"Asia"},"AS":{"iso2":"AS","iso3":"ASM","name":"American Samoa","continent":"Oceania"},"AQ":{"iso2":"AQ","iso3":"ATA","name":"Antarctica","continent":"Antarctic"},"TF":{"iso2":"TF","iso3":"ATF","name":"Territory of the French Southern and Antarctic Lands","continent":"Antarctic"},"AG":{"iso2":"AG","iso3":"ATG","name":"Antigua and Barbuda","continent":"Americas"},"AU":{"iso2":"AU","iso3":"AUS","name":"Commonwealth of Australia","continent":"Oceania"},"AT":{"iso2":"AT","iso3":"AUT","name":"Republic of Austria","continent":"Europe"},"AZ":{"iso2":"AZ","iso3":"AZE","name":"Republic of Azerbaijan","continent":"Asia"},"BI":{"iso2":"BI","iso3":"BDI","name":"Republic of Burundi","continent":"Africa"},"BE":{"iso2":"BE","iso3":"BEL","name":"Kingdom of Belgium","continent":"Europe"},"BJ":{"iso2":"BJ","iso3":"BEN","name":"Republic of Benin","continent":"Africa"},"BF":{"iso2":"BF","iso3":"BFA","name":"Burkina Faso","continent":"Africa"},"BD":{"iso2":"BD","iso3":"BGD","name":"People's Republic of Bangladesh","continent":"Asia"},"BG":{"iso2":"BG","iso3":"BGR","name":"Republic of Bulgaria","continent":"Europe"},"BH":{"iso2":"BH","iso3":"BHR","name":"Kingdom of Bahrain","continent":"Asia"},"BS":{"iso2":"BS","iso3":"BHS","name":"Commonwealth of the Bahamas","continent":"Americas"},"BA":{"iso2":"BA","iso3":"BIH","name":"Bosnia and Herzegovina","continent":"Europe"},"BL":{"iso2":"BL","iso3":"BLM","name":"Collectivity of Saint Barth\u00e9lemy","continent":"Americas"},"SH":{"iso2":"SH","iso3":"SHN","name":"Saint Helena, Ascension and Tristan da Cunha","continent":"Africa"},"BY":{"iso2":"BY","iso3":"BLR","name":"Republic of Belarus","continent":"Europe"},"BZ":{"iso2":"BZ","iso3":"BLZ","name":"Belize","continent":"Americas"},"BM":{"iso2":"BM","iso3":"BMU","name":"Bermuda","continent":"Americas"},"BO":{"iso2":"BO","iso3":"BOL","name":"Plurinational State of Bolivia","continent":"Americas"},"BQ":{"iso2":"BQ","iso3":"BES","name":"Bonaire, Sint Eustatius and Saba","continent":"Americas"},"BR":{"iso2":"BR","iso3":"BRA","name":"Federative Republic of Brazil","continent":"Americas"},"BB":{"iso2":"BB","iso3":"BRB","name":"Barbados","continent":"Americas"},"BN":{"iso2":"BN","iso3":"BRN","name":"Nation of Brunei, Abode of Peace","continent":"Asia"},"BT":{"iso2":"BT","iso3":"BTN","name":"Kingdom of Bhutan","continent":"Asia"},"BV":{"iso2":"BV","iso3":"BVT","name":"Bouvet Island","continent":"Antarctic"},"BW":{"iso2":"BW","iso3":"BWA","name":"Republic of Botswana","continent":"Africa"},"CF":{"iso2":"CF","iso3":"CAF","name":"Central African Republic","continent":"Africa"},"CA":{"iso2":"CA","iso3":"CAN","name":"Canada","continent":"Americas"},"CC":{"iso2":"CC","iso3":"CCK","name":"Territory of the Cocos (Keeling) Islands","continent":"Oceania"},"CH":{"iso2":"CH","iso3":"CHE","name":"Swiss Confederation","continent":"Europe"},"CL":{"iso2":"CL","iso3":"CHL","name":"Republic of Chile","continent":"Americas"},"CN":{"iso2":"CN","iso3":"CHN","name":"People's Republic of China","continent":"Asia"},"CI":{"iso2":"CI","iso3":"CIV","name":"Republic of C\u00f4te d'Ivoire","continent":"Africa"},"CM":{"iso2":"CM","iso3":"CMR","name":"Republic of Cameroon","continent":"Africa"},"CD":{"iso2":"CD","iso3":"COD","name":"Democratic Republic of the Congo","continent":"Africa"},"CG":{"iso2":"CG","iso3":"COG","name":"Republic of the Congo","continent":"Africa"},"CK":{"iso2":"CK","iso3":"COK","name":"Cook Islands","continent":"Oceania"},"CO":{"iso2":"CO","iso3":"COL","name":"Republic of Colombia","continent":"Americas"},"KM":{"iso2":"KM","iso3":"COM","name":"Union of the Comoros","continent":"Africa"},"CV":{"iso2":"CV","iso3":"CPV","name":"Republic of Cabo Verde","continent":"Africa"},"CR":{"iso2":"CR","iso3":"CRI","name":"Republic of Costa Rica","continent":"Americas"},"CU":{"iso2":"CU","iso3":"CUB","name":"Republic of Cuba","continent":"Americas"},"CW":{"iso2":"CW","iso3":"CUW","name":"Country of Cura\u00e7ao","continent":"Americas"},"CX":{"iso2":"CX","iso3":"CXR","name":"Territory of Christmas Island","continent":"Oceania"},"KY":{"iso2":"KY","iso3":"CYM","name":"Cayman Islands","continent":"Americas"},"CY":{"iso2":"CY","iso3":"CYP","name":"Republic of Cyprus","continent":"Europe"},"CZ":{"iso2":"CZ","iso3":"CZE","name":"Czech Republic","continent":"Europe"},"DE":{"iso2":"DE","iso3":"DEU","name":"Federal Republic of Germany","continent":"Europe"},"DJ":{"iso2":"DJ","iso3":"DJI","name":"Republic of Djibouti","continent":"Africa"},"DM":{"iso2":"DM","iso3":"DMA","name":"Commonwealth of Dominica","continent":"Americas"},"DK":{"iso2":"DK","iso3":"DNK","name":"Kingdom of Denmark","continent":"Europe"},"DO":{"iso2":"DO","iso3":"DOM","name":"Dominican Republic","continent":"Americas"},"DZ":{"iso2":"DZ","iso3":"DZA","name":"People's Democratic Republic of Algeria","continent":"Africa"},"EC":{"iso2":"EC","iso3":"ECU","name":"Republic of Ecuador","continent":"Americas"},"EG":{"iso2":"EG","iso3":"EGY","name":"Arab Republic of Egypt","continent":"Africa"},"ER":{"iso2":"ER","iso3":"ERI","name":"State of Eritrea","continent":"Africa"},"EH":{"iso2":"EH","iso3":"ESH","name":"Sahrawi Arab Democratic Republic","continent":"Africa"},"ES":{"iso2":"ES","iso3":"ESP","name":"Kingdom of Spain","continent":"Europe"},"EE":{"iso2":"EE","iso3":"EST","name":"Republic of Estonia","continent":"Europe"},"ET":{"iso2":"ET","iso3":"ETH","name":"Federal Democratic Republic of Ethiopia","continent":"Africa"},"FI":{"iso2":"FI","iso3":"FIN","name":"Republic of Finland","continent":"Europe"},"FJ":{"iso2":"FJ","iso3":"FJI","name":"Republic of Fiji","continent":"Oceania"},"FK":{"iso2":"FK","iso3":"FLK","name":"Falkland Islands","continent":"Americas"},"FR":{"iso2":"FR","iso3":"FRA","name":"French Republic","continent":"Europe"},"FO":{"iso2":"FO","iso3":"FRO","name":"Faroe Islands","continent":"Europe"},"FM":{"iso2":"FM","iso3":"FSM","name":"Federated States of Micronesia","continent":"Oceania"},"GA":{"iso2":"GA","iso3":"GAB","name":"Gabonese Republic","continent":"Africa"},"GB":{"iso2":"GB","iso3":"GBR","name":"United Kingdom of Great Britain and Northern Ireland","continent":"Europe"},"GE":{"iso2":"GE","iso3":"GEO","name":"Georgia","continent":"Asia"},"GG":{"iso2":"GG","iso3":"GGY","name":"Bailiwick of Guernsey","continent":"Europe"},"GH":{"iso2":"GH","iso3":"GHA","name":"Republic of Ghana","continent":"Africa"},"GI":{"iso2":"GI","iso3":"GIB","name":"Gibraltar","continent":"Europe"},"GN":{"iso2":"GN","iso3":"GIN","name":"Republic of Guinea","continent":"Africa"},"GP":{"iso2":"GP","iso3":"GLP","name":"Guadeloupe","continent":"Americas"},"GM":{"iso2":"GM","iso3":"GMB","name":"Republic of the Gambia","continent":"Africa"},"GW":{"iso2":"GW","iso3":"GNB","name":"Republic of Guinea-Bissau","continent":"Africa"},"GQ":{"iso2":"GQ","iso3":"GNQ","name":"Republic of Equatorial Guinea","continent":"Africa"},"GR":{"iso2":"GR","iso3":"GRC","name":"Hellenic Republic","continent":"Europe"},"GD":{"iso2":"GD","iso3":"GRD","name":"Grenada","continent":"Americas"},"GL":{"iso2":"GL","iso3":"GRL","name":"Greenland","continent":"Americas"},"GT":{"iso2":"GT","iso3":"GTM","name":"Republic of Guatemala","continent":"Americas"},"GF":{"iso2":"GF","iso3":"GUF","name":"Guiana","continent":"Americas"},"GU":{"iso2":"GU","iso3":"GUM","name":"Guam","continent":"Oceania"},"GY":{"iso2":"GY","iso3":"GUY","name":"Co-operative Republic of Guyana","continent":"Americas"},"HK":{"iso2":"HK","iso3":"HKG","name":"Hong Kong Special Administrative Region of the People's Republic of China","continent":"Asia"},"HM":{"iso2":"HM","iso3":"HMD","name":"Heard Island and McDonald Islands","continent":"Antarctic"},"HN":{"iso2":"HN","iso3":"HND","name":"Republic of Honduras","continent":"Americas"},"HR":{"iso2":"HR","iso3":"HRV","name":"Republic of Croatia","continent":"Europe"},"HT":{"iso2":"HT","iso3":"HTI","name":"Republic of Haiti","continent":"Americas"},"HU":{"iso2":"HU","iso3":"HUN","name":"Hungary","continent":"Europe"},"ID":{"iso2":"ID","iso3":"IDN","name":"Republic of Indonesia","continent":"Asia"},"IM":{"iso2":"IM","iso3":"IMN","name":"Isle of Man","continent":"Europe"},"IN":{"iso2":"IN","iso3":"IND","name":"Republic of India","continent":"Asia"},"IO":{"iso2":"IO","iso3":"IOT","name":"British Indian Ocean Territory","continent":"Africa"},"IE":{"iso2":"IE","iso3":"IRL","name":"Republic of Ireland","continent":"Europe"},"IR":{"iso2":"IR","iso3":"IRN","name":"Islamic Republic of Iran","continent":"Asia"},"IQ":{"iso2":"IQ","iso3":"IRQ","name":"Republic of Iraq","continent":"Asia"},"IS":{"iso2":"IS","iso3":"ISL","name":"Iceland","continent":"Europe"},"IL":{"iso2":"IL","iso3":"ISR","name":"State of Israel","continent":"Asia"},"IT":{"iso2":"IT","iso3":"ITA","name":"Italian Republic","continent":"Europe"},"JM":{"iso2":"JM","iso3":"JAM","name":"Jamaica","continent":"Americas"},"JE":{"iso2":"JE","iso3":"JEY","name":"Bailiwick of Jersey","continent":"Europe"},"JO":{"iso2":"JO","iso3":"JOR","name":"Hashemite Kingdom of Jordan","continent":"Asia"},"JP":{"iso2":"JP","iso3":"JPN","name":"Japan","continent":"Asia"},"KZ":{"iso2":"KZ","iso3":"KAZ","name":"Republic of Kazakhstan","continent":"Asia"},"KE":{"iso2":"KE","iso3":"KEN","name":"Republic of Kenya","continent":"Africa"},"KG":{"iso2":"KG","iso3":"KGZ","name":"Kyrgyz Republic","continent":"Asia"},"KH":{"iso2":"KH","iso3":"KHM","name":"Kingdom of Cambodia","continent":"Asia"},"KI":{"iso2":"KI","iso3":"KIR","name":"Independent and Sovereign Republic of Kiribati","continent":"Oceania"},"KN":{"iso2":"KN","iso3":"KNA","name":"Federation of Saint Christopher and Nevisa","continent":"Americas"},"KR":{"iso2":"KR","iso3":"KOR","name":"Republic of Korea","continent":"Asia"},"XK":{"iso2":"XK","iso3":"UNK","name":"Republic of Kosovo","continent":"Europe"},"KW":{"iso2":"KW","iso3":"KWT","name":"State of Kuwait","continent":"Asia"},"LA":{"iso2":"LA","iso3":"LAO","name":"Lao People's Democratic Republic","continent":"Asia"},"LB":{"iso2":"LB","iso3":"LBN","name":"Lebanese Republic","continent":"Asia"},"LR":{"iso2":"LR","iso3":"LBR","name":"Republic of Liberia","continent":"Africa"},"LY":{"iso2":"LY","iso3":"LBY","name":"State of Libya","continent":"Africa"},"LC":{"iso2":"LC","iso3":"LCA","name":"Saint Lucia","continent":"Americas"},"LI":{"iso2":"LI","iso3":"LIE","name":"Principality of Liechtenstein","continent":"Europe"},"LK":{"iso2":"LK","iso3":"LKA","name":"Democratic Socialist Republic of Sri Lanka","continent":"Asia"},"LS":{"iso2":"LS","iso3":"LSO","name":"Kingdom of Lesotho","continent":"Africa"},"LT":{"iso2":"LT","iso3":"LTU","name":"Republic of Lithuania","continent":"Europe"},"LU":{"iso2":"LU","iso3":"LUX","name":"Grand Duchy of Luxembourg","continent":"Europe"},"LV":{"iso2":"LV","iso3":"LVA","name":"Republic of Latvia","continent":"Europe"},"MO":{"iso2":"MO","iso3":"MAC","name":"Macao Special Administrative Region of the People's Republic of China","continent":"Asia"},"MF":{"iso2":"MF","iso3":"MAF","name":"Saint Martin","continent":"Americas"},"MA":{"iso2":"MA","iso3":"MAR","name":"Kingdom of Morocco","continent":"Africa"},"MC":{"iso2":"MC","iso3":"MCO","name":"Principality of Monaco","continent":"Europe"},"MD":{"iso2":"MD","iso3":"MDA","name":"Republic of Moldova","continent":"Europe"},"MG":{"iso2":"MG","iso3":"MDG","name":"Republic of Madagascar","continent":"Africa"},"MV":{"iso2":"MV","iso3":"MDV","name":"Republic of the Maldives","continent":"Asia"},"MX":{"iso2":"MX","iso3":"MEX","name":"United Mexican States","continent":"Americas"},"MH":{"iso2":"MH","iso3":"MHL","name":"Republic of the Marshall Islands","continent":"Oceania"},"MK":{"iso2":"MK","iso3":"MKD","name":"Republic of Macedonia","continent":"Europe"},"ML":{"iso2":"ML","iso3":"MLI","name":"Republic of Mali","continent":"Africa"},"MT":{"iso2":"MT","iso3":"MLT","name":"Republic of Malta","continent":"Europe"},"MM":{"iso2":"MM","iso3":"MMR","name":"Republic of the Union of Myanmar","continent":"Asia"},"ME":{"iso2":"ME","iso3":"MNE","name":"Montenegro","continent":"Europe"},"MN":{"iso2":"MN","iso3":"MNG","name":"Mongolia","continent":"Asia"},"MP":{"iso2":"MP","iso3":"MNP","name":"Commonwealth of the Northern Mariana Islands","continent":"Oceania"},"MZ":{"iso2":"MZ","iso3":"MOZ","name":"Republic of Mozambique","continent":"Africa"},"MR":{"iso2":"MR","iso3":"MRT","name":"Islamic Republic of Mauritania","continent":"Africa"},"MS":{"iso2":"MS","iso3":"MSR","name":"Montserrat","continent":"Americas"},"MQ":{"iso2":"MQ","iso3":"MTQ","name":"Martinique","continent":"Americas"},"MU":{"iso2":"MU","iso3":"MUS","name":"Republic of Mauritius","continent":"Africa"},"MW":{"iso2":"MW","iso3":"MWI","name":"Republic of Malawi","continent":"Africa"},"MY":{"iso2":"MY","iso3":"MYS","name":"Malaysia","continent":"Asia"},"YT":{"iso2":"YT","iso3":"MYT","name":"Department of Mayotte","continent":"Africa"},"NA":{"iso2":"NA","iso3":"NAM","name":"Republic of Namibia","continent":"Africa"},"NC":{"iso2":"NC","iso3":"NCL","name":"New Caledonia","continent":"Oceania"},"NE":{"iso2":"NE","iso3":"NER","name":"Republic of Niger","continent":"Africa"},"NF":{"iso2":"NF","iso3":"NFK","name":"Territory of Norfolk Island","continent":"Oceania"},"NG":{"iso2":"NG","iso3":"NGA","name":"Federal Republic of Nigeria","continent":"Africa"},"NI":{"iso2":"NI","iso3":"NIC","name":"Republic of Nicaragua","continent":"Americas"},"NU":{"iso2":"NU","iso3":"NIU","name":"Niue","continent":"Oceania"},"NL":{"iso2":"NL","iso3":"NLD","name":"Kingdom of the Netherlands","continent":"Europe"},"NO":{"iso2":"NO","iso3":"NOR","name":"Kingdom of Norway","continent":"Europe"},"NP":{"iso2":"NP","iso3":"NPL","name":"Federal Democratic Republic of Nepal","continent":"Asia"},"NR":{"iso2":"NR","iso3":"NRU","name":"Republic of Nauru","continent":"Oceania"},"NZ":{"iso2":"NZ","iso3":"NZL","name":"New Zealand","continent":"Oceania"},"OM":{"iso2":"OM","iso3":"OMN","name":"Sultanate of Oman","continent":"Asia"},"PK":{"iso2":"PK","iso3":"PAK","name":"Islamic Republic of Pakistan","continent":"Asia"},"PA":{"iso2":"PA","iso3":"PAN","name":"Republic of Panama","continent":"Americas"},"PN":{"iso2":"PN","iso3":"PCN","name":"Pitcairn Group of Islands","continent":"Oceania"},"PE":{"iso2":"PE","iso3":"PER","name":"Republic of Peru","continent":"Americas"},"PH":{"iso2":"PH","iso3":"PHL","name":"Republic of the Philippines","continent":"Asia"},"PW":{"iso2":"PW","iso3":"PLW","name":"Republic of Palau","continent":"Oceania"},"PG":{"iso2":"PG","iso3":"PNG","name":"Independent State of Papua New Guinea","continent":"Oceania"},"PL":{"iso2":"PL","iso3":"POL","name":"Republic of Poland","continent":"Europe"},"PR":{"iso2":"PR","iso3":"PRI","name":"Commonwealth of Puerto Rico","continent":"Americas"},"KP":{"iso2":"KP","iso3":"PRK","name":"Democratic People's Republic of Korea","continent":"Asia"},"PT":{"iso2":"PT","iso3":"PRT","name":"Portuguese Republic","continent":"Europe"},"PY":{"iso2":"PY","iso3":"PRY","name":"Republic of Paraguay","continent":"Americas"},"PS":{"iso2":"PS","iso3":"PSE","name":"State of Palestine","continent":"Asia"},"PF":{"iso2":"PF","iso3":"PYF","name":"French Polynesia","continent":"Oceania"},"QA":{"iso2":"QA","iso3":"QAT","name":"State of Qatar","continent":"Asia"},"RE":{"iso2":"RE","iso3":"REU","name":"R\u00e9union Island","continent":"Africa"},"RO":{"iso2":"RO","iso3":"ROU","name":"Romania","continent":"Europe"},"RU":{"iso2":"RU","iso3":"RUS","name":"Russian Federation","continent":"Europe"},"RW":{"iso2":"RW","iso3":"RWA","name":"Republic of Rwanda","continent":"Africa"},"SA":{"iso2":"SA","iso3":"SAU","name":"Kingdom of Saudi Arabia","continent":"Asia"},"SD":{"iso2":"SD","iso3":"SDN","name":"Republic of the Sudan","continent":"Africa"},"SN":{"iso2":"SN","iso3":"SEN","name":"Republic of Senegal","continent":"Africa"},"SG":{"iso2":"SG","iso3":"SGP","name":"Republic of Singapore","continent":"Asia"},"GS":{"iso2":"GS","iso3":"SGS","name":"South Georgia and the South Sandwich Islands","continent":"Antarctic"},"SJ":{"iso2":"SJ","iso3":"SJM","name":"Svalbard og Jan Mayen","continent":"Europe"},"SB":{"iso2":"SB","iso3":"SLB","name":"Solomon Islands","continent":"Oceania"},"SL":{"iso2":"SL","iso3":"SLE","name":"Republic of Sierra Leone","continent":"Africa"},"SV":{"iso2":"SV","iso3":"SLV","name":"Republic of El Salvador","continent":"Americas"},"SM":{"iso2":"SM","iso3":"SMR","name":"Most Serene Republic of San Marino","continent":"Europe"},"SO":{"iso2":"SO","iso3":"SOM","name":"Federal Republic of Somalia","continent":"Africa"},"PM":{"iso2":"PM","iso3":"SPM","name":"Saint Pierre and Miquelon","continent":"Americas"},"RS":{"iso2":"RS","iso3":"SRB","name":"Republic of Serbia","continent":"Europe"},"SS":{"iso2":"SS","iso3":"SSD","name":"Republic of South Sudan","continent":"Africa"},"ST":{"iso2":"ST","iso3":"STP","name":"Democratic Republic of S\u00e3o Tom\u00e9 and Pr\u00edncipe","continent":"Africa"},"SR":{"iso2":"SR","iso3":"SUR","name":"Republic of Suriname","continent":"Americas"},"SK":{"iso2":"SK","iso3":"SVK","name":"Slovak Republic","continent":"Europe"},"SI":{"iso2":"SI","iso3":"SVN","name":"Republic of Slovenia","continent":"Europe"},"SE":{"iso2":"SE","iso3":"SWE","name":"Kingdom of Sweden","continent":"Europe"},"SZ":{"iso2":"SZ","iso3":"SWZ","name":"Kingdom of Swaziland","continent":"Africa"},"SX":{"iso2":"SX","iso3":"SXM","name":"Sint Maarten","continent":"Americas"},"SC":{"iso2":"SC","iso3":"SYC","name":"Republic of Seychelles","continent":"Africa"},"SY":{"iso2":"SY","iso3":"SYR","name":"Syrian Arab Republic","continent":"Asia"},"TC":{"iso2":"TC","iso3":"TCA","name":"Turks and Caicos Islands","continent":"Americas"},"TD":{"iso2":"TD","iso3":"TCD","name":"Republic of Chad","continent":"Africa"},"TG":{"iso2":"TG","iso3":"TGO","name":"Togolese Republic","continent":"Africa"},"TH":{"iso2":"TH","iso3":"THA","name":"Kingdom of Thailand","continent":"Asia"},"TJ":{"iso2":"TJ","iso3":"TJK","name":"Republic of Tajikistan","continent":"Asia"},"TK":{"iso2":"TK","iso3":"TKL","name":"Tokelau","continent":"Oceania"},"TM":{"iso2":"TM","iso3":"TKM","name":"Turkmenistan","continent":"Asia"},"TL":{"iso2":"TL","iso3":"TLS","name":"Democratic Republic of Timor-Leste","continent":"Asia"},"TO":{"iso2":"TO","iso3":"TON","name":"Kingdom of Tonga","continent":"Oceania"},"TT":{"iso2":"TT","iso3":"TTO","name":"Republic of Trinidad and Tobago","continent":"Americas"},"TN":{"iso2":"TN","iso3":"TUN","name":"Tunisian Republic","continent":"Africa"},"TR":{"iso2":"TR","iso3":"TUR","name":"Republic of Turkey","continent":"Asia"},"TV":{"iso2":"TV","iso3":"TUV","name":"Tuvalu","continent":"Oceania"},"TW":{"iso2":"TW","iso3":"TWN","name":"Republic of China (Taiwan)","continent":"Asia"},"TZ":{"iso2":"TZ","iso3":"TZA","name":"United Republic of Tanzania","continent":"Africa"},"UG":{"iso2":"UG","iso3":"UGA","name":"Republic of Uganda","continent":"Africa"},"UA":{"iso2":"UA","iso3":"UKR","name":"Ukraine","continent":"Europe"},"UM":{"iso2":"UM","iso3":"UMI","name":"United States Minor Outlying Islands","continent":"Americas"},"UY":{"iso2":"UY","iso3":"URY","name":"Oriental Republic of Uruguay","continent":"Americas"},"US":{"iso2":"US","iso3":"USA","name":"United States of America","continent":"Americas"},"UZ":{"iso2":"UZ","iso3":"UZB","name":"Republic of Uzbekistan","continent":"Asia"},"VA":{"iso2":"VA","iso3":"VAT","name":"Vatican City State","continent":"Europe"},"VC":{"iso2":"VC","iso3":"VCT","name":"Saint Vincent and the Grenadines","continent":"Americas"},"VE":{"iso2":"VE","iso3":"VEN","name":"Bolivarian Republic of Venezuela","continent":"Americas"},"VG":{"iso2":"VG","iso3":"VGB","name":"Virgin Islands","continent":"Americas"},"VI":{"iso2":"VI","iso3":"VIR","name":"Virgin Islands of the United States","continent":"Americas"},"VN":{"iso2":"VN","iso3":"VNM","name":"Socialist Republic of Vietnam","continent":"Asia"},"VU":{"iso2":"VU","iso3":"VUT","name":"Republic of Vanuatu","continent":"Oceania"},"WF":{"iso2":"WF","iso3":"WLF","name":"Territory of the Wallis and Futuna Islands","continent":"Oceania"},"WS":{"iso2":"WS","iso3":"WSM","name":"Independent State of Samoa","continent":"Oceania"},"YE":{"iso2":"YE","iso3":"YEM","name":"Republic of Yemen","continent":"Asia"},"ZA":{"iso2":"ZA","iso3":"ZAF","name":"Republic of South Africa","continent":"Africa"},"ZM":{"iso2":"ZM","iso3":"ZMB","name":"Republic of Zambia","continent":"Africa"},"ZW":{"iso2":"ZW","iso3":"ZWE","name":"Republic of Zimbabwe","continent":"Africa"}}
// +build ignore
// This program generates countries/data.go. It can be invoked by running
// go generate
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"text/template"
"time"
)
type Country struct {
ISO2 string `json:"iso2"`
ISO3 string `json:"iso3"`
Name string `json:"name"`
Continent string `json:"continent"`
}
type CountryList map[string]Country
func main() {
j, err := ioutil.ReadFile("countries.json")
die(err)
data := make(CountryList, 0)
err = json.Unmarshal(j, &data)
die(err)
f, err := os.Create("data.go")
die(err)
defer f.Close()
packageTemplate.Execute(f, struct {
Timestamp time.Time
Countries CountryList
}{
Timestamp: time.Now(),
Countries: data,
})
}
func die(err error) {
if err != nil {
log.Fatal(err)
}
}
var packageTemplate = template.Must(template.New("").Parse(`// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// {{ .Timestamp }}
package countries
var countries = make(map[string]Country)
func init() {
{{- range .Countries }}
countries[{{ printf "%q" .ISO2 }}] = Country{
ISO2: {{ printf "%q" .ISO2 }},
ISO3: {{ printf "%q" .ISO3 }},
Name: {{ printf "%q" .Name }},
Continent: {{ printf "%q" .Continent }},
}
{{- end }}
}
`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment