countries

package
v0.0.0-...-03678d5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2016 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var Countries = reduceCountries(countries)

Countries exports all countries available in the package

Functions

This section is empty.

Types

type Country

type Country struct {
	// Alpha2 refers to a 2-letter alpha ISO 3166-1 Code
	Alpha2 string `json:"alpha2"`
	// Alpha3 refers to a 3-letter alpha ISO 3166-1 Code
	Alpha3 string `json:"alpha3"`
	// Numeric refers to a 3-digit numeric ISO 3166-1 Code
	Numeric string `json:"numeric"`
	// Currencies refers to all currencies used in a country
	Currencies []currencies.Currency `json:"currencies"`
	// DialingCodes refers to all dialing / calling phone codes / prefixes
	DialingCodes []string `json:"dialing_codes"`
	// Languages refers to all languages spoken in a country
	Languages []languages.Language `json:"languages"`
	// Name refers to the common english name of a country
	Name string `json:"name"`
}

Country materializes a country object, with its name and ISO identifiers

func Lookup

func Lookup(query Country) []Country

Lookup retrieves a list of countries satisfying the criteria(s) given in arguments

Criteria such as `Alpha3`, `Alpha2` and `Numeric` return a unique Country, if valid Criteria `Name` is matched against inclusion (e.g. "United Kingdom" will be matched by "United" Criteria `Currencies` and `Languages` use Lookup() function for the related type

Example

ExampleLookup illustrates several lookups

package main

import (
	"fmt"

	"github.com/KtorZ/go-iso-codes/currencies"
	"github.com/KtorZ/go-iso-codes/languages"
)

// sort ascendently sort a slice of countries on the Alpha3
func sort(xs []Country) []Country {
	var _xs []Country
sort:
	for _, a := range xs {
		for i, b := range _xs {
			if a.Alpha3 < b.Alpha3 {
				_xs = append(_xs[:i], append([]Country{a}, _xs[i:]...)...)
				continue sort
			}
		}

		_xs = append(_xs, a)
	}

	return _xs
}

// ExampleLookup illustrates several lookups
func main() {
	results := Lookup(Country{Alpha3: "NLD"})
	fmt.Println(results)

	results = Lookup(Country{
		Languages: []languages.Language{
			languages.Language{Alpha3: "nld"},
		},
		Currencies: []currencies.Currency{
			currencies.Currency{Alpha3: "EUR"},
		},
	})
	fmt.Println(sort(results))

}
Output:

[{NL NLD 528 [{EUR 978 2 Euro}] [+31] [{nl nld Dutch}] Netherlands}]
[{BE BEL 056 [{EUR 978 2 Euro}] [+32] [{nl nld Dutch} {fr fra French} {de deu German}] Belgium} {NL NLD 528 [{EUR 978 2 Euro}] [+31] [{nl nld Dutch}] Netherlands}]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL