geo

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package geo implements a location lookup by name or IP address.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Languages are the only name extracted from the
	// MaxMind database for searching by place name.
	Languages = []string{"en", "de", "fr", "es"}
)

Functions

func DownloadDB

func DownloadDB(dbPath, URL string) (fetched bool, err error)

DownloadDB downloads URL to path

Types

type DB

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

DB looks up location data by IP or city. It is a suture.Service and should be passed to a suture.Supervisor.

func New

func New(dir, dbPath string) *DB

New DB. Reads MaxMind database at dbPath and saves its own data in dir. Both must exist when Open() or Serve() is called.

func (*DB) Lookup

func (gdb *DB) Lookup(ip net.IP) (Location, error)

Lookup returns a Location for an IP address.

func (*DB) Open

func (gdb *DB) Open() error

Open a GeoLite2 database for reading.

func (*DB) Search

func (gdb *DB) Search(query string) ([]Location, error)

Search returns Locations whose names match query.

func (*DB) Serve

func (gdb *DB) Serve()

Serve opens the database.

func (*DB) Stop

func (gdb *DB) Stop()

Stop closes the database.

type Location

type Location struct {
	Town      string  `json:"town" xml:"town"`
	Region    string  `json:"region" xml:"region"`
	Country   string  `json:"country" xml:"country"`
	Postcode  string  `json:"postcode" xml:"postcode"`
	Timezone  string  `json:"timezone" xml:"timezone"`
	Latitude  float64 `json:"latitude" xml:"latitude"`
	Longitude float64 `json:"longitude" xml:"longitude"`
}

Location is the structure returned by the API.

func (Location) IsZero

func (l Location) IsZero() bool

IsZero returns true if latitude or longitude is not set.

func (Location) String

func (l Location) String() string

String returns the long name of a Location.

type Updater

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

Updater checks for an update to the database every 12 hours. Updater is a suture.Service and should be managed by a suture.Supervisor.

func NewUpdater

func NewUpdater(dbPath, URL string) *Updater

NewUpdater creates an initialised Updater.

func (*Updater) Serve

func (u *Updater) Serve()

Serve starts the Updater.

func (*Updater) Stop

func (u *Updater) Stop()

Stop stops the Updater.

Jump to

Keyboard shortcuts

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