Gountries provides: Countries (ISO-3166-1), Country Subdivisions(ISO-3166-2), Currencies (ISO 4217), Geo Coordinates(ISO-6709) as well as translations, country borders and other stuff exposed as struct data.
I'm planning on using your library as part of an API and I was going to make a few changes to get faster lookups and embed the data directly into the binary to make it easier to deploy. Interested in a pull request?
Planned features:
Embed the country data from the YAML files using go-bindata so that the deployment remains a single binary without relying on an external data directory. This would be backwards compatible so that when you populateCountries or populateSubdivisions it checks the bindata first and then falls back to the data directory.
Use a bidirectional tree map from the gods library so that lookups by either country name or alpha code are more efficient.
Support returning either all of the data or a particular subset of countries as a struct that is easily marshaled to JSON. This is useful to populate a frontend web UI for entering billing/shipping addresses.
This could simplify some of the query functions by using the tree to do lookups, rather than looping through all of the available data.
I'm going to fork your library and work on this a little bit. Let me know if you have any other ideas.
go get doesn't fetch content of data directory so it's empty after obtaining a project
example code fails with panic panic: Error loading Countries because it expects current directory of executable to contain data directory. But it's actually not there but inside github.com/pariz/gountries
This makes the library pretty unsuitable for use in real-world applications. Currently, in order to get, e.g., a Country's list of Subdivisions, it creates a new Query every time you call it. This is horribly inefficient.
Probably the best way to solve this is make one Query and either make it a global variable that is initialized during package initialization, or allow it to be explicitly initialized if that isn't acceptable.
Remove the error formatting which introduces the gountries error part or
Make it customizable ?
Sometimes we want to return the error from gountries to expose what's wrong to the API user, but the gountries part can create confusion as to what's wrong.
Good Go style is to use lower-case letters to start error messages, and start with the package name, which makes them easily composable. See https://golang.org/doc/effective_go.html#errors
I noticed that your data contains unicode symbols in data/json/countries/ while \u<number> form is used in countries.json. Has it been done intentionally?
Is it possible to use plain unicode in countries.json too? I believe it's better for readability and grammar checking.
The methods for countries sometimes take pointer receivers, and sometimes take struct receivers. They should be made consistent. My preference would be to use pointers everywhere in this library, because the data structures are frequently large and shouldn't be needlessly copied.
Would you be willing to accept a PR that adds translated country names to NameToAlpha2? I've run into several cases where lookups by name have failed but the spelling variant is among the translations.