maxmind

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxMindDownloadPathQuery   = "/app/geoip_download?edition_id=%s&license_key=%s&suffix=%s"
	DBArchiveDownloadSuffix    = "tar.gz"
	DBSHA256FileDownloadSuffix = "tar.gz.sha256"
	DBSuffix                   = "mmdb"
)

Variables

View Source
var (
	MaxMindHost        = "https://download.maxmind.com"
	MaxMindDownloadURL = fmt.Sprintf("%s%s", MaxMindHost, MaxMindDownloadPathQuery)
)
View Source
var (
	// ErrCountryDBNotLoaded is returned when the country database is not loaded.
	ErrCountryDBNotLoaded = errors.New("country database not loaded")

	// ErrCityDBNotLoaded is returned when the city database is not loaded.
	ErrCityDBNotLoaded = errors.New("city database not loaded")

	// ErrASNDBNotLoaded is returned when the ASN database is not loaded.
	ErrASNDBNotLoaded = errors.New("ASN database not loaded")

	// ErrLicenseKeyRequired is returned when the MaxMind license key is missing.
	ErrLicenseKeyRequired = errors.New("WAYPOINT_MAXMIND_LICENSE_KEY is required")

	// ErrChecksumMismatch is returned when the downloaded file checksum does not match.
	ErrChecksumMismatch = errors.New("checksum mismatch")

	// ErrEmptySHA256File is returned when the SHA256 file is empty.
	ErrEmptySHA256File = errors.New("empty SHA256 file")

	// ErrInvalidSHA256File is returned when the SHA256 file format is invalid.
	ErrInvalidSHA256File = errors.New("invalid SHA256 file format")

	// ErrDBDownloadFailed is returned when downloading databases fails and no local copies exist.
	ErrDBDownloadFailed = errors.New("failed to download databases and no existing files found")

	// ErrDBOpenFailed is returned when opening a database file fails.
	ErrDBOpenFailed = errors.New("failed to open database")

	// ErrInvalidIP is returned when an invalid IP address is provided.
	ErrInvalidIP = errors.New("invalid IP address")
)

Functions

This section is empty.

Types

type Client

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

Client handles MaxMind database operations and lookups.

func NewClient

func NewClient(cfg *config.MaxMindConfig, dataDir string) *Client

NewClient creates a new MaxMind client.

func (*Client) ASN

func (c *Client) ASN(ip net.IP) (*geoip2.ASN, error)

ASN looks up ASN information for an IP.

func (*Client) City

func (c *Client) City(ip net.IP) (*geoip2.City, error)

City looks up city information for an IP.

func (*Client) Close

func (c *Client) Close()

Close closes all open database readers.

func (*Client) Country

func (c *Client) Country(ip net.IP) (*geoip2.Country, error)

Country looks up country information for an IP.

func (*Client) DownloadAllDB

func (c *Client) DownloadAllDB() error

DownloadAllDB downloads all configured databases.

func (*Client) IP2ASN

func (c *Client) IP2ASN(ipStr string) (IPASN, error)

IP2ASN looks up ASN information for an IP address.

func (*Client) IP2City

func (c *Client) IP2City(ipStr string) (IPCity, error)

IP2City looks up city information for an IP address.

func (*Client) IP2Country

func (c *Client) IP2Country(ipStr string) (IPCountry, error)

IP2Country looks up country information for an IP address.

func (*Client) IP2Geo

func (c *Client) IP2Geo(ipStr string) (GeoIP, error)

IP2Geo looks up all geographic information for an IP address.

func (*Client) Load

func (c *Client) Load() error

Load loads all databases from disk.

func (*Client) RunDBDownloadJob

func (c *Client) RunDBDownloadJob(ctx context.Context)

RunDBDownloadJob starts the background job for downloading databases.

type DBType

type DBType string

DBType represents the type of MaxMind database.

const (
	DBTypeCountry DBType = "GeoLite2-Country"
	DBTypeCity    DBType = "GeoLite2-City"
	DBTypeASN     DBType = "GeoLite2-ASN"
)

type GeoIP

type GeoIP struct {
	IPCity
	IPASN
	IP     string `json:"ip"`
	Remark string `json:"remark,omitempty"`
}

GeoIP represents complete geographic and ASN information for an IP.

type IPASN

type IPASN struct {
	IP           string `json:"ip"`
	ASN          uint   `json:"asn"`
	Organization string `json:"organization"`
}

IPASN represents ASN information for an IP.

type IPCity

type IPCity struct {
	City string `json:"city"`
	IPCountry
	Timezone  string  `json:"timezone"`
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
}

IPCity represents city information for an IP.

type IPCountry

type IPCountry struct {
	IP                  string `json:"ip"`
	Country             string `json:"country"`
	Continent           string `json:"continent"`
	ISOCountryCode      string `json:"iso_country_code"`
	ISOContinentCode    string `json:"iso_continent_code"`
	IsAnonymousProxy    bool   `json:"is_anonymous_proxy"`
	IsSatelliteProvider bool   `json:"is_satellite_provider"`
}

IPCountry represents country information for an IP.

Jump to

Keyboard shortcuts

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