Skip to content

shanemhansen/gogeo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Go bindings to the GeoIP city database

gogeo allows you you to access a GeoIP city database to determine Geographical information from an IP address.

Features

  • IPv4 support
  • IPv6 support
  • GeoRecord support
  • Unlike other libraries, doesn't read the whole database into memory
  • Fine grained control over database open modes, caching, etc.
  • Works with go net.Addr's, which simplifies integration with go network programs.

Limitations

  • cgo based (not suitable for app engine deployments)

Setup

  • Install libgeoip1 libgeoip-dev (on ubuntu)
  • Download the geolite city database (either ipv4 or ipv6)
  • go get -u github.com/shanemhansen/gogeo

Example usage

  • Look at the unit tests
package main
import "github.com/shanemhansen/gogeo"
import "net"
import "fmt"

func main() {
    db, err := gogeo.Open("/usr/share/GeoIP/GeoLiteCity.dat", gogeo.MemoryCache)
    if err != nil {
        panic(err)
    }
    addr, err := net.ResolveIPAddr("ip4", "google.com")
    record := db.RecordByIPAddr(addr)
    fmt.Printf("hello, from %s", record.CountryCode)
   }

About

Go bindings to the GeoIP database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages