geoip2

package
v0.0.0-...-20aadb4 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2018 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const AsnDB = "http://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz"

AsnDB download link

View Source
const CityDB = "http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz"

CityDB download link

Variables

View Source
var DefaultClient = &Client{
	DBLocationDir: "maxminddb",
	Timeout:       time.Second * 15,
	MaxConnect:    0x64,
}

DefaultClient ...

Functions

This section is empty.

Types

type Client

type Client struct {
	DBLocationDir string        // DBLocationDir is used to store mmdb files
	MaxConnect    int           // max synchronously lookup
	Timeout       time.Duration // lookup duration

	AsnDB  *maxminddb.Reader
	CityDB *maxminddb.Reader
	// contains filtered or unexported fields
}

Client ...

func (*Client) Close

func (c *Client) Close() error

Close database

func (*Client) DBMeta

func (c *Client) DBMeta() ([]DBMeta, error)

DBMeta return database metadata

func (*Client) Init

func (c *Client) Init() error

Init and verify the database, if none exists, download it

func (*Client) Lookup

func (c *Client) Lookup(ipStr string) (*Result, error)

Lookup for ip geo information

func (*Client) UpdateDB

func (c *Client) UpdateDB()

UpdateDB when remote database update, used with cron

type DBMeta

type DBMeta struct {
	Version      string    `json:"version"`
	IPVersion    string    `json:"ipVersion"`
	DatabaseType string    `json:"type"`
	BuildEpoch   time.Time `json:"buildEpoch"`
}

DBMeta metadata

type Result

type Result struct {
	Continent struct {
		Code  string `maxminddb:"code" json:"code"`
		Names struct {
			ZhCN string `maxminddb:"zh-CN" json:"zh-cn"`
			En   string `maxminddb:"en" json:"en"`
		} `maxminddb:"names" json:"names"`
	} `maxminddb:"continent" json:"continent"`
	Country struct {
		ISOCode string `maxminddb:"iso_code" json:"iso_code"`
		Names   struct {
			ZhCN string `maxminddb:"zh-CN" json:"zh-cn"`
			En   string `maxminddb:"en" json:"en"`
		} `maxminddb:"names" json:"names"`
	} `maxminddb:"country" json:"country"`
	City struct {
		Names struct {
			ZhCN string `maxminddb:"zh-CN" json:"zh-cn"`
			En   string `maxminddb:"en" json:"en"`
		} `maxminddb:"names" json:"names"`
	} `maxminddb:"city" json:"city"`
	Subdivisions []struct {
		ISOCode string `maxminddb:"iso_code" json:"iso_code"`
		Names   struct {
			ZhCN string `maxminddb:"zh-CN" json:"zh-cn"`
			En   string `maxminddb:"en" json:"en"`
		} `maxminddb:"names" json:"names"`
	} `maxminddb:"subdivisions" json:"subdivisions"`
	Location struct {
		TimeZone       string  `maxminddb:"time_zone" json:"time_zone"`
		Latitude       float32 `maxminddb:"latitude" json:"latitude"`
		Longitude      float32 `maxminddb:"longitude" json:"longitude"`
		AccuracyRadius int     `maxminddb:"accuracy_radius" json:"accuracy_radius"`
	} `maxminddb:"location" json:"location"`
	RegisteredCountry struct {
		ISOCode string `maxminddb:"iso_code" json:"iso_code"`
		Names   struct {
			ZhCN string `maxminddb:"zh-CN" json:"zh-cn"`
			En   string `maxminddb:"en" json:"en"`
		} `maxminddb:"names" json:"names"`
	} `maxminddb:"registered_country" json:"registered_country"`
	Organization string `maxminddb:"autonomous_system_organization" json:"organization"`
}

Result of lookup

Jump to

Keyboard shortcuts

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