Skip to content
Snippets Groups Projects
Select Git revision
  • master
1 result

country.go

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    country.go 4.63 KiB
    package country
    
    import (
    	"encoding/json"
    	"fmt"
    	"github.com/alediaferia/gocountries"
    	"net/http"
    )
    
    /*
    URL list for 'REST Countries API' to be modified to query needs
    */
    const BASEURL = "https://restcountries.eu/"
    const BORDERURL = "https://restcountries.eu/rest/v2/alpha?codes="
    
    // Country struct for JSON encoding
    type Country []struct {
    	Name           string    `json:"name"`
    	TopLevelDomain []string  `json:"topLevelDomain"`
    	Alpha2Code     string    `json:"alpha2Code"`
    	Alpha3Code     string    `json:"alpha3Code"`
    	CallingCodes   []string  `json:"callingCodes"`
    	Capital        string    `json:"capital"`
    	AltSpellings   []string  `json:"altSpellings"`
    	Region         string    `json:"region"`
    	Subregion      string    `json:"subregion"`
    	Population     int       `json:"population"`
    	Latlng         []float64 `json:"latlng"`
    	Demonym        string    `json:"demonym"`
    	Area           float64   `json:"area"`
    	Gini           float64   `json:"gini"`
    	Timezones      []string  `json:"timezones"`
    	Borders        []string  `json:"borders"`
    	NativeName     string    `json:"nativeName"`
    	NumericCode    string    `json:"numericCode"`
    	Currencies     []struct {
    		Code   string `json:"code"`
    		Name   string `json:"name"`
    		Symbol string `json:"symbol"`
    	} `json:"currencies"`
    	Languages []struct {
    		Iso6391    string `json:"iso639_1"`
    		Iso6392    string `json:"iso639_2"`
    		Name       string `json:"name"`
    		NativeName string `json:"nativeName"`
    	} `json:"languages"`
    	Translations struct {
    		De string `json:"de"`
    		Es string `json:"es"`
    		Fr string `json:"fr"`
    		Ja string `json:"ja"`
    		It string `json:"it"`
    		Br string `json:"br"`
    		Pt string `json:"pt"`
    		Nl string `json:"nl"`
    		Hr string `json:"hr"`
    		Fa string `json:"fa"`
    	} `json:"translations"`
    	Flag          string `json:"flag"`
    	RegionalBlocs []struct {
    		Acronym       string        `json:"acronym"`
    		Name          string        `json:"name"`
    		OtherAcronyms []interface{} `json:"otherAcronyms"`
    		OtherNames    []interface{} `json:"otherNames"`
    	} `json:"regionalBlocs"`
    	Cioc string `json:"cioc"`
    }
    
    /*
    GetCurrency returns a string of specified Country's currency code e.g.(NOK, USD, EUR...)