geo

package
v0.0.0-...-da267cc Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package geo provides the Lat/Long distance calculation functionality and GeoIP lookup functionality used to determine the best peers to use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownloadDB

func DownloadDB(outputPath string, apiKey string) error

DownloadDB will fetch a new geoip database from maxmind and install it, uncompressed, into the configured geodb_path config file path usually defined in the configuration files.

Types

type DB

type DB struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

DB handles opening and querying from the maxmind Cities geo memory mapped database (.mmdb) file.

func New

func New(path string) (*DB, error)

New opens the .mmdb file for querying and sets up the ellipsoid configuration for more accurate geo queries

func (*DB) Close

func (db *DB) Close()

Close close the underlying memory mapped file

func (*DB) GetLocation

func (db *DB) GetLocation(ip net.IP) Location

GetLocation returns the geo location of the input IP addr

type DummyProvider

type DummyProvider struct{}

DummyProvider is used when we dont want to use this feature. It will always return 0, 0

func (*DummyProvider) Close

func (d *DummyProvider) Close()

Close does nothing for the dummy provider

func (*DummyProvider) DownloadDB

func (d *DummyProvider) DownloadDB(_ string, _ string) error

DownloadDB does nothing for the dummy provider

func (*DummyProvider) GetLocation

func (d *DummyProvider) GetLocation(_ net.IP) Location

GetLocation will always return 0, 0 coordinates

type LatLong

type LatLong struct {
	Latitude  float64
	Longitude float64
}

func LatLongFromString

func LatLongFromString(s string) LatLong

LatLongFromString will return a LatLong from a string formatted like N,-N

func (*LatLong) Scan

func (ll *LatLong) Scan(v interface{}) error

Scan implements the sql.Scanner interface for conversion to our custom type

func (LatLong) String

func (ll LatLong) String() string

String returns a comma separated lat long pair string

func (*LatLong) Value

func (ll *LatLong) Value() (driver.Value, error)

Value implements the driver.Valuer interface for our custom type

type Location

type Location struct {
	ISOCode string
	LatLong LatLong
	// Autonomous system number (ASN)
	ASN uint32
	// Autonomous system (AS) name
	AS string
}

Location provides a container and some helper functions for location data

type Provider

type Provider interface {
	GetLocation(ip net.IP) Location
	Close()
}

Provider defines our interface for querying geo location data stores

Jump to

Keyboard shortcuts

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