geoip

package
v0.0.0-...-d5b31fc Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2020 License: MIT Imports: 15 Imported by: 0

README

GeoIP

lookup asn, country, city for IP address by using GeoIP2 database

Usage

    geo, err := geoip.NewGeo("", "")
    if err != nil {
        log.Fatalln(err)
    }

    // query IP geo info
    info := geo.GetGeoInfo("8.8.8.8", "zh-CN")
    pretty(info)

    // update local geo database
    geo.Update()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Geo

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

Geo is an implemention of Handler interface

func NewGeo

func NewGeo(fcity, fasn string) (*Geo, error)

NewGeo is exported

func (*Geo) GetGeoInfo

func (g *Geo) GetGeoInfo(addr, lang string) (info *GeoInfo)

GetGeoInfo implement Handler interface note: always return a non-nil *GeoInfo

func (*Geo) Metadata

func (g *Geo) Metadata() map[string]maxminddb.Metadata

Metadata implement Handler interface

func (*Geo) Update

func (g *Geo) Update() error

Update implement Handler interface

type GeoInfo

type GeoInfo struct {
	IP          string `json:"ip" bson:"ip"`
	Continent   string `json:"continent" bson:"continent"`
	Country     string `json:"country" bson:"country"`
	CountryISO  string `json:"country_iso" bson:"country_iso"`
	City        string `json:"city" bson:"city"`
	TimeZone    string `json:"timezone" bson:"timezone"`
	Orgnization string `json:"orgnization" bson:"orgnization"`
}

GeoInfo is exported

type Handler

type Handler interface {
	GetGeoInfo(addr, lang string) *GeoInfo // query geo info for given address & lang["de","en","es","fr","ja","pt-BR","ru","zh-CN"]

	Metadata() map[string]maxminddb.Metadata // current geo data info (version,epoch,size,lang,etc)

	Update() error // update geo data
}

Handler represents geo data interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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