Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pariz/gountries
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.
https://github.com/pariz/gountries
Last synced: 24 days ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/pariz/gountries
- Owner: pariz
- License: mit
- Created: 2016-01-13T08:04:18.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-04-27T15:50:21.000Z (about 1 year ago)
- Last Synced: 2024-01-31T05:16:07.773Z (4 months ago)
- Language: Go
- Homepage:
- Size: 2.15 MB
- Stars: 401
- Watchers: 16
- Forks: 67
- Open Issues: 14
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Lists
- awesome-go - gountries - Package that exposes country and subdivision data. (Miscellaneous / Uncategorized)
- awesome-go - gountries - Package that exposes country and subdivision data. (Miscellaneous / Uncategorized)
- awesome-go-extra - gountries - 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.|353|63|13|2016-01-13T08:04:18Z|2022-08-12T12:16:42Z| (Microsoft Office / Uncategorized)
- awesome-go-cn - gountries
- awesome-go-zh - gountries
- awesome-go - gountries - Package that exposes country and subdivision data. (Miscellaneous / Uncategorized)
- awesome-go-cn - gountries
- awesome-go - gountries - | - | - | (Miscellaneous / Strings)
- fucking-awesome-go - :octocat: gountries - A package that exposes country and subdivision data. :star: 87 :fork_and_knife: 4 (Miscellaneous / Advanced Console UIs)
- awesome-go - gountries - Package that exposes country and subdivision data. (Miscellaneous / Uncategorized)
- awesome-go-projects - gountries - Package that exposes country and subdivision data. (Miscellaneous / Uncategorized)
- awesome-go - gountries - Package that exposes country and subdivision data. (Miscellaneous / Uncategorized)
- awesome-go - gountries - Package that exposes country and subdivision data. (Miscellaneous / Advanced Console UIs)
- awesome-go - gountries - A package that exposes country and subdivision data. (Miscellaneous / Advanced Console UIs)
- awesome-go-with-framework - gountries - Package that exposes country and subdivision data. (Miscellaneous / Strings)
- awesome-go - gountries - Package that exposes country and subdivision data. (Miscellaneous / Uncategorized)
- awesome-go-cn - gountries
- go-awesome-cn-star - gountries
- zero-alloc-awesome-go - gountries - Package that exposes country and subdivision data. (Miscellaneous / Uncategorized)
- awesome-go - gountries - Package that exposes country and subdivision data. (Miscellaneous / Strings)
- awesome-go. - gountries - Package that exposes country and subdivision data. (Miscellaneous / Advanced Console UIs)
- awesome-go - gountries - Package that exposes country and subdivision data. (<span id="其他-miscellaneous">其他 Miscellaneous</span> / <span id="高级控制台用户界面-advanced-console-uis">高级控制台用户界面 Advanced Console UIs</span>)
- awesome-go-with-stars - gountries - Package that exposes country and subdivision data. (Miscellaneous / Uncategorized)
- awesome-go - gountries - Package that exposes country and subdivision data. (Miscellaneous / Uncategorized)
- repo-1316-awesome-go-cn - gountries
- repo-1211-awesome-go-cn - gountries
- awesome-Char - gountries - Package that exposes country and subdivision data. (Miscellaneous / Uncategorized)
- awesome-reader - gountries - Package that exposes country and subdivision data. (Miscellaneous / Strings)
- awesome-go - gountries - Package that exposes country and subdivision data. (Miscellaneous / Strings)
- Go-awesome - gountries - Package that exposes country and subdivision data. (Miscellaneous / Uncategorized)
- awesome-go - gountries - A package that exposes country and subdivision data. (Miscellaneous / Advanced Console UIs)
- awesome-go-handwritten - gountries - Package that exposes country and subdivision data. (Miscellaneous / Advanced Console UIs)
- awesome-go2 - gountries - Package that exposes country and subdivision data. (Miscellaneous / Advanced Console UIs)
- awesome-go - gountries - Package that exposes country and subdivision data. (Miscellaneous / Uncategorized)
- awesome-go - gountries - Package that exposes country and subdivision data. - :arrow_down:8 - :star:103 (Miscellaneous / Strings)
- awesome-go - gountries - Package that exposes country and subdivision data. (Miscellaneous / Uncategorized)
- awesome-go - gountries - A package that exposes country and subdivision data. (Miscellaneous / Advanced Console UIs)
- awesome-go - gountries - Package that exposes country and subdivision data. (Miscellaneous / Uncategorized)
- awesome-go-cn - gountries
- awesome-go-stars - gountries - Package that exposes country and subdivision data. (Miscellaneous / Uncategorized)
- awesome-go-zh - gountries
- awesome-go - gountries - Package that exposes country and subdivision data. (Miscellaneous / Uncategorized)
- awesome-go - gountries - Package that exposes country and subdivision data. (Miscellaneous / Uncategorized)
- awesome-go-cn - gountries
- awesome-go - gountries - 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. - ★ 181 (Miscellaneous)
README
# gountries
[![wercker status](https://app.wercker.com/status/909d6a059d7d0b49b74ec8b658f97df4/s/master "wercker status")](https://app.wercker.com/project/bykey/909d6a059d7d0b49b74ec8b658f97df4) [![codecov.io](https://codecov.io/github/pariz/gountries/coverage.svg?branch=master)](https://codecov.io/github/pariz/gountries?branch=master) [![Go Report Card](https://goreportcard.com/badge/pariz/gountries)](https://goreportcard.com/report/pariz/gountries)
Inspired by the [countries](https://github.com/hexorx/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](https://github.com/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
```go
package mainimport (
"fmt"
"github.com/pariz/gountries"
)func main() {
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 Sverigefmt.Println(sweden.Translations["DEU"].Common) // Output: Schweden
fmt.Println(sweden.Translations["DEU"].Official) // Output: Königreich Schweden
}```
## A bit more advanced
```go
package mainimport (
"fmt"
"github.com/pariz/gountries"
)func main() {
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 := gountries.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.1937864547901distance = 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?