gountries alternatives and similar packages
Based on the "Miscellaneous" category.
Alternatively, view gountries alternatives based on common mentions on social networks and blogs.
-
go-formatter
A curated list of awesome Go frameworks, libraries and software -
golang-standards/project-layout
Standard Go Project Layout -
archiver
Easily create & extract archives, and compress & decompress files of various formats -
ardanlabs/service
Starter code for writing web services in Go using Kubernetes. -
go-multierror
A Go (golang) package for representing a list of errors as a single error. -
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 🥚 -
xstrings
Implements string functions widely used in other languages but absent in Go. -
go-shortid
Super short, fully unique, non-sequential and URL friendly Ids -
health
An easy to use, extensible health check library for Go applications. -
container
A lightweight yet powerful IoC dependency injection container for the Go programming language -
golang-templates/seed
Go application GitHub repository template. -
banner
An easy way to add useful startup banners into your Go applications -
go-starter
An opinionated production-ready SQL-/Swagger-first RESTful JSON API written in Go, highly integrated with VSCode DevContainers by allaboutapps. -
antch
Antch, a fast, powerful and extensible web crawling & scraping framework for Go -
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, IOC/NOC and FIFA codes, VERY VERY FAST, compatible with Databases/JSON/BSON/GOB/XML/CSV, Emoji countries flags and currencies support, Unicode CLDR. -
healthcheck
An simple, easily extensible and concurrent health-check library for Go services
Clean code begins in your IDE with SonarLint
* 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?