geolocation

package
v0.36.2 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: BSD-3-Clause Imports: 28 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type City

type City struct {
	GeoNameID int `gorm:"column:geoname_id"`
	CityName  string
}

type Country

type Country struct {
	CountryISOCode string `gorm:"column:country_iso_code"`
	CountryName    string
}

type GeoNames added in v0.26.1

type GeoNames struct {
	GeoNameID           int    `gorm:"column:geoname_id"`
	LocaleCode          string `gorm:"column:locale_code"`
	ContinentCode       string `gorm:"column:continent_code"`
	ContinentName       string `gorm:"column:continent_name"`
	CountryIsoCode      string `gorm:"column:country_iso_code"`
	CountryName         string `gorm:"column:country_name"`
	Subdivision1IsoCode string `gorm:"column:subdivision_1_iso_code"`
	Subdivision1Name    string `gorm:"column:subdivision_1_name"`
	Subdivision2IsoCode string `gorm:"column:subdivision_2_iso_code"`
	Subdivision2Name    string `gorm:"column:subdivision_2_name"`
	CityName            string `gorm:"column:city_name"`
	MetroCode           string `gorm:"column:metro_code"`
	TimeZone            string `gorm:"column:time_zone"`
	IsInEuropeanUnion   string `gorm:"column:is_in_european_union"`
}

func (*GeoNames) TableName added in v0.26.1

func (*GeoNames) TableName() string

type Geolocation

type Geolocation interface {
	Lookup(ip net.IP) (*Record, error)
	GetAllCountries() ([]Country, error)
	GetCitiesByCountry(countryISOCode string) ([]City, error)
	Stop() error
}

func NewGeolocation

func NewGeolocation(ctx context.Context, dataDir string, autoUpdate bool) (Geolocation, error)

type Mock added in v0.36.0

type Mock struct{}

func (*Mock) GetAllCountries added in v0.36.0

func (g *Mock) GetAllCountries() ([]Country, error)

func (*Mock) GetCitiesByCountry added in v0.36.0

func (g *Mock) GetCitiesByCountry(countryISOCode string) ([]City, error)

func (*Mock) Lookup added in v0.36.0

func (g *Mock) Lookup(ip net.IP) (*Record, error)

func (*Mock) Stop added in v0.36.0

func (g *Mock) Stop() error

type Record

type Record struct {
	City struct {
		GeonameID uint `maxminddb:"geoname_id"`
		Names     struct {
			En string `maxminddb:"en"`
		} `maxminddb:"names"`
	} `maxminddb:"city"`
	Continent struct {
		GeonameID uint   `maxminddb:"geoname_id"`
		Code      string `maxminddb:"code"`
	} `maxminddb:"continent"`
	Country struct {
		GeonameID uint   `maxminddb:"geoname_id"`
		ISOCode   string `maxminddb:"iso_code"`
	} `maxminddb:"country"`
}

type SqliteStore

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

SqliteStore represents a location storage backed by a Sqlite DB.

func NewSqliteStore

func NewSqliteStore(ctx context.Context, dataDir string, dbPath string) (*SqliteStore, error)

func (*SqliteStore) GetAllCountries

func (s *SqliteStore) GetAllCountries() ([]Country, error)

GetAllCountries returns a list of all countries in the store.

func (*SqliteStore) GetCitiesByCountry

func (s *SqliteStore) GetCitiesByCountry(countryISOCode string) ([]City, error)

GetCitiesByCountry retrieves a list of cities from the store based on the given country ISO code.

Jump to

Keyboard shortcuts

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