countries

package
v0.0.0-...-a0e6cc7 Latest Latest
Warning

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

Go to latest
Published: May 16, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheFlags

func CacheFlags(countries []Country, cacheDir string, dimensions FlagDimensions, cb func(current int, total int, countryName string)) error

func FormatCurrencies

func FormatCurrencies(currencies map[string]CurrencyInfo) string

func FormatFlagFileName

func FormatFlagFileName(countryName string) string

func FormatInt

func FormatInt(number int) string

func FormatLanguages

func FormatLanguages(langs map[string]string) string

func FormatLatLng

func FormatLatLng(latlng []float32) string

func FormatTz

func FormatTz(tzs []string) string

func ReadFlag

func ReadFlag(fileName string, cacheDir string) (string, error)

Read flag from cache by its name

func SaveData

func SaveData(data []Country, cacheDir string, fileName string) error

Types

type CacheDir

type CacheDir func() (string, error)

type Config

type Config struct {
	Url        string
	Query      string
	CacheFile  string
	CacheDir   CacheDir
	Dimensions FlagDimensions
}

type Country

type Country struct {
	Name struct {
		Common   string `json:"common"`
		Official string `json:"official"`
	} `json:"name"`
	//          Lord have mercy
	Currencies  map[string]CurrencyInfo `json:"currencies"`
	Capital     []string                `json:"capital"`
	Flag        string                  `json:"flag"`
	Population  int                     `json:"population"`
	Languages   map[string]string       `json:"languages"`
	Region      string                  `json:"region"`
	Subregion   string                  `json:"subregion"`
	Timezones   []string                `json:"timezones"`
	Latlng      []float32               `json:"latlng"`
	CapitalInfo struct {
		Latlng []float32 `json:"latlng"`
	} `json:"capitalInfo"`
	Tld   []string `json:"tld"`
	Flags struct {
		Png string `json:"png"`
		Svg string `json:"svg"`
	} `json:"flags"`
}

func ExactMatch

func ExactMatch(countries []Country, exp string) (Country, error)

func FindByCapital

func FindByCapital(countries []Country, exp string) (Country, error)

func FindByName

func FindByName(countries []Country, exp string) (Country, error)

func FuzzyMatch

func FuzzyMatch(countries []Country, exp string) (Country, error)

func GetData

func GetData(url string, query string) ([]Country, error)

func Random

func Random(countries []Country) Country

func ReadData

func ReadData(cacheDir string, fileName string) ([]Country, error)

func (Country) FlagAscii

func (c Country) FlagAscii(converter *convert.ImageConverter, options *convert.Options) (string, error)

Generate flag ASCII from remote url image and return it as string

func (Country) Print

func (c Country) Print()

TODO: Make getters for Country properties that are troublesome (like capital that is sometimes empty slice)

func (Country) PrintFlag

func (c Country) PrintFlag(cacheDir string) error

Print flag from cache

func (Country) PrintFlagRemote

func (c Country) PrintFlagRemote(width int, height int) error

type CurrencyInfo

type CurrencyInfo struct {
	Name   string `json:"name"`
	Symbol string `json:"symbol"`
}

type FlagDimensions

type FlagDimensions struct {
	Width  int
	Height int
}

Jump to

Keyboard shortcuts

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