ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - 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.
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 st...
Visit Site

GitHub - 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.

GitHub - 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.

gountries

wercker status codecov.io Go Report Card

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

package main

import (
	"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 Sverige

	fmt.Println(sweden.Translations["DEU"].Common)   // Output: Schweden
	fmt.Println(sweden.Translations["DEU"].Official) // Output: Königreich Schweden
}

A bit more advanced

package main

import (
	"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.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)
  • Measurement between coordinates
  • GeoJSON information
  • Suggestions?

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory