gountries alternatives and similar packages
Based on the "Miscellaneous" category.
Alternatively, view gountries alternatives based on common mentions on social networks and blogs.
-
go-restful-api
An idiomatic Go REST API starter kit (boilerplate) following the SOLID principles and Clean Architecture -
ghorg
Quickly clone an entire org/users repositories into one directory - Supports GitHub, GitLab, Bitbucket, and more 🐇🥚 -
IOC-golang
IOC-golang is a powerful golang dependency injection framework that provides a complete implementation of IoC containers. -
container
A lightweight yet powerful IoC dependency injection container for the Go programming language -
go-starter
An opinionated production-ready SQL-/Swagger-first RESTful JSON API written in Go, highly integrated with VSCode DevContainers by allaboutapps. -
countries
Countries - ISO-639, ISO-3166 countries codes with subdivisions and names, ISO-4217 currency designators, ITU-T E.164 IDD phone codes, countries capitals, UN M.49 codes, IANA ccTLD countries domains, FIPS, IOC/NOC and FIFA codes, VERY VERY FAST, compatible with Databases/JSON/BSON/GOB/XML/CSV, Emoji countries flags and currencies, Unicode CLDR.
InfluxDB - Purpose built for real-time analytics at any scale.
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of gountries or a related project?
README
gountries
Inspired by the countries gem for ruby.
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.
All data is derived from the pariz/countries repo.
This is currently a work in progress, so things may change. More stuff will be added
Installation
go get github.com/pariz/gountries
Examples
Basic
import (
"github.com/pariz/gountries"
"fmt"
)
query := gountries.New()
/////////////////
// Find sweden //
/////////////////
sweden, _ := query.FindCountryByName("sweden")
// sweden, _ := query.FindCountryByAlpha("SE")
// sweden, _ := query.FindCountryByAlpha("SWE")
fmt.Println(sweden.Name.Common) // Output: Sweden
fmt.Println(sweden.Name.Official) // Output: Konungariket Sverige
fmt.Println(sweden.Translations["DEU"].Common) // Output: Schweden
fmt.Println(sweden.Translations["DEU"].Official) // Output: Königreich Schweden
A bit more advanced
import (
"github.com/pariz/gountries"
"fmt"
)
query := gountries.New()
////////////////////////////////////////////
// Find the bordering countries of Sweden //
////////////////////////////////////////////
sweden, _ := query.FindCountryByAlpha("SWE") // "SE" also works..
// Get the bordering countries of sweden
for _, country := range sweden.BorderingCountries() {
fmt.Println(country.Name.Common)
}
// Output:
// Finland
// Norway
////////////////////////////////////
// Find all subdivisons for Sweden //
////////////////////////////////////
subdivisions := sweden.SubDivisions()
for _, subdivision := range subdivisions {
fmt.Println(subdivision.Name)
}
// Output:
// Västerbottens län
// Uppsala län
// Södermanlands län
// Gotlands län
// Dalarnas län
// ...
//////////////////////////////////////////////////////////
// Find all countries bordering Germany and Switzerland //
//////////////////////////////////////////////////////////
countryQuery := Country{
Borders: []string{
"DEU",
"CHE",
},
}
countries := query.FindCountries(countryQuery)
for _, c := range countries {
fmt.Println(c.Name.Common)
}
// Output:
// Austria
// France
///////////////////////////////////////////////////////////////////
// Calculate distance between Sweden and Germany (in Kilometers) //
///////////////////////////////////////////////////////////////////
se, _ := query.FindCountryByAlpha("SWE")
de, _ := query.FindCountryByAlpha("DEU")
distance := gountries.MeasureDistanceHaversine(se, de)
//distance := MeasureDistancePythagoras(se, de)
fmt.Println(distance)
// Output:
// 1430.1937864547901
distance = gountries.CalculateHaversine(
se.Coordinates.MaxLatitude, se.Coordinates.MaxLongitude,
de.Coordinates.MinLatitude, de.Coordinates.MinLongitude)
fmt.Println(distance)
// Output:
// 2641.26145088825
Using packed data
The data in the data/yaml
subdirectory is embedded using go-bindata. Once you include this library in your project, you won't need to access the data directory. To add or update the data, make changes to the YAML files then run:
go-bindata -pkg gountries data/yaml/*
Testing
Has a pretty solid test coverage but is constantly improving.
Todo
- [ ] Province/County querying (partially complete)
- [x] Measurement between coordinates
- [ ] GeoJSON information
- [ ] Suggestions?