libgeo

package
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2015 License: BSD-3-Clause, Apache-2.0 Imports: 2 Imported by: 0

README

h2. General Description

p{width:500px}. This is the Go implementation of the "Maxmind":http://www.maxmind.com/app/ip-location GeoIP API. It is incomplete and work in progress the initial goal is support only two of the database types - the City Lite and Country Lite. The only supported method is loading the full db on startup into memory (memory cache).

h3. Supported Access Methods

* In Memory (Load(string))

h3. Supported Database Formats

* Country Edition    (dbType=1)
* City Edition REV 0 (dbType=6)
* City Edition REV 1 (dbType=2)

h3. Supported Lookups

* By IP Address (GetLocationByIP(string))
* By IP Number  (GetLocationByIPNum(uint32))

h3. Supported Responses

* CountryCode string (available in all databases)
* CountryName string (available in all databases)
* City string
* Region string
* PostalCode string
* Latitude float32
* Longitude float32

h3. To Do
* Implement better error handling (report the error on load and lookups)
* Better returns, country edition has only code and name (perhaps use interfaces)
* Add test cases and benchmarking
* Add support for more database formats

h3. Build

make (See Makefile for more details)

h3. Example

./example DBFILE IPADDRESS (i.e. ./example GeoIP.dat 1.1.1.1)

h3. Usage

Please see example.go for a complete example of how to use this library.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddrToNum

func AddrToNum(ip string) uint32

Convert ip address to an int representation

Types

type GeoIP

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

These are some structs

func Load

func Load(filename string) (gi *GeoIP, err error)

Load the database file in memory, detect the db format and setup the GeoIP struct

func (*GeoIP) GetLocationByIP

func (gi *GeoIP) GetLocationByIP(ip string) *Location

Lookup by IP address and return location

func (*GeoIP) GetLocationByIPNum

func (gi *GeoIP) GetLocationByIPNum(ipNum uint32) *Location

Lookup by IP number and return location

type Location

type Location struct {
	CountryCode string // If country ed. only country info is filled
	CountryName string // If country ed. only country info is filled
	Region      string
	City        string
	PostalCode  string
	Latitude    float32
	Longitude   float32
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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