geoip

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2023 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindMirrors

func FindMirrors(location *Location) []*common.Mirror

Find mirrors that suit the given location.

Rules:

  • Prefer mirrors of the same country.
  • Then prefer mirrors of the same continent.
  • Fallback to the default mirror.
  • If multiple mirrors in the same country/continent, order by distance via latitude/longitude.
  • Append the default to the last as the fallback.
  • If location is nil, then return the default mirror.

Types

type Location

type Location struct {
	ContinentCode string
	CountryCode   string
	Latitude      float64
	Longitude     float64
}

func LookupIP

func LookupIP(ip net.IP) (*Location, error)

Lookup the location data in MMDB for the IP address.

type Point

type Point struct {
	Latitude  float64
	Longitude float64
}

type Record

type Record struct {
	Continent struct {
		// Two-letter code
		Code string `maxminddb:"code"`
	} `maxminddb:"continent"`
	Country struct {
		// Two-letter code
		Code string `maxminddb:"iso_code"`
	} `maxminddb:"country"`
	Location struct {
		Latitude  float64 `maxminddb:"latitude"`
		Longitude float64 `maxminddb:"longitude"`
	} `maxminddb:"location"`
}

MaxMind and DB-IP use the same schema for the selected fields here.

Jump to

Keyboard shortcuts

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