countries

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

README

countries

Go package to retrieve country data by the ISO 3166-1 alpha-2 code.


Install

go get github.com/RobinToubi/countries

Use

Continent name by country code
func GetContinentByCountry(countryCode string) string, error
Continent name To Country code list
func GetCountryCodesByContinent(continent string) []string

Simple example

package main

import (
	"fmt"
	"github.com/RobinToubi/countries"
)

func main() {
	// Instantiate the service
	countryService := countries.InstanceCountry()
	
	// Retrieve a continent by the country code
	continent, _ := countryService.GetContinentByCountry("HK")
	fmt.Println(continent) // "Asia"
	
	// Retrieve country codes by a continent name
	cCodes, _ := countryService.GetCountryCodesByContinent("Asia")
	fmt.Println(cCodes) // [AF AM AZ BH BD BT BN KH CN CX CC CY GE HK IN ID IR IQ IL JP JO KZ KP KR KW KG LA LB MY MV MN MM NP OM PK PH QA RU SA SG LK SY TW TJ TH TR TM AE UZ VN YE]
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Country

type Country struct {
	// ISO 3166-1 alpha-2 code
	Code      string
	Name      string
	Continent string
}

type CountryData

type CountryData struct {
	// contains filtered or unexported fields
}

func InstanceCountry

func InstanceCountry() *CountryData

func (*CountryData) GetContinentByCountry

func (data *CountryData) GetContinentByCountry(countryCode string) (string, error)

func (*CountryData) GetCountryCodeByEnglishName

func (data *CountryData) GetCountryCodeByEnglishName(countryName string) (string, error)

func (*CountryData) GetCountryCodesByContinent

func (data *CountryData) GetCountryCodesByContinent(continent string) ([]string, error)

Jump to

Keyboard shortcuts

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