geo

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LangEnglish     = "en"
	LangChinese     = "zh-CN"
	LangRussian     = "ru"
	LangJapanese    = "ja"
	LangGerman      = "de"
	LangFrench      = "fr"
	LangSpanish     = "es"
	LangPortuguese  = "pt-BR"
	LangPersian     = "fa"
	LangKorean      = "ko"
	DefaultLanguage = LangChinese
)

Supported languages for geolocation information.

Variables

View Source
var DatabaseLanguage string
View Source
var IDInfos map[string]string

IDInfos contains mapping from GeoNameID to its respective information.

View Source
var Language string

Language to be used for names.

View Source
var NameInfos map[string]map[string]map[string]string

NameInfos contains a multilevel mapping from field -> language -> name -> information.

Functions

func GetNameInfos

func GetNameInfos(field string, lang string) map[string]string

GetNameInfos retrieves geolocation information based on a given field and language.

func LoadData

func LoadData(lang string, data ...string) map[string]string

LoadData populates geolocation data based on a given language and data sources.

func SetDBLanguage

func SetDBLanguage(lang string) error

SetDBLanguage sets the language for the database. It returns an error if the provided language is not supported.

func SetLanguage

func SetLanguage(lang string) error

SetLanguage sets the global language for geolocation information.

func Translate

func Translate(field, text string) string

Translate translates the provided text from the database language to the application's current language. If the text cannot be translated, it returns the original text.

Types

type Info

type Info struct {
	GeoNameID         int               `json:"geoname_id"`           // GeoNameID is the ID of the record in the GeoNames database.
	Names             map[string]string `json:"names"`                // Names is map of locale codes to the name in that locale.
	Code              string            `json:"code"`                 // Code is the Code for Continent.
	IsoCode           string            `json:"iso_code"`             // IsoCode is the ISO Code for the country or subdivision.
	IsInEuropeanUnion bool              `json:"is_in_european_union"` // IsInEuropeanUnion is true if the country is a member state of the European Union.
	ConnectionID      int               `json:"-"`                    // ConnectionID is the GeoNameID for the Connection Type.
	CountryID         int               `json:"-"`                    // CountryID is the GeoNameID for the Country.
	SubdivisionIDs    []int             `json:"-"`                    // SubdivisionIDs is an array of GeoNameIDs for the Subdivisions(regions).
}

Info represents the geolocation information.

func GetInfoByID

func GetInfoByID(geoNameID int) (*Info, bool)

GetInfoByID retrieves geolocation info by its GeoNameID.

func GetInfoByName

func GetInfoByName(field, name string) (*Info, bool)

GetInfoByName retrieves geolocation info by its name.

func ParseGeoInfo

func ParseGeoInfo(s string) (*Info, bool)

ParseGeoInfo parses a geolocation info from a formatted string. Format: GeoNameID, Names, Code, ISO-Code, IsInEuropeanUnion, ConnectionID, CountryID, SubdivisionIDs

func ParseInfoFromMMDB

func ParseInfoFromMMDB(m map[string]interface{}, disableExtraData bool) (*Info, bool)

ParseInfoFromMMDB extracts geolocation info from a MMDB map.

func (*Info) Map

func (g *Info) Map(selectLanguages string) map[string]interface{}

Map converts the geolocation info into a map structure.

func (*Info) Name

func (g *Info) Name(lang string) string

Name returns the name of the geolocation info in the specified language.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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