Skip to content

This project can search for IP information through Maxmind geoip2 databases. It supports to be automatically downloaded and updated the latest Maxmind databases in background.

License

gjbae1212/go-geoip2

Repository files navigation

go-geoip2

Go Report Card license

Overview

This project can search for IP information through Maxmind geoip2 databases.

This project is built using Reader in oschwald/maxminddb-golang.

You can read Maxmind databases using a local file.
Either you can read Maxmind databases using Maxmind download URL.

If you use reading databases with Maxmind download URL(only support gzip link), it is possible to update the latest databases periodically.
It mean you will be automatically downloaded and updated to target-path in background.

So you don't need to update the latest Maxmind databases manually, So very useful.

[warning] Maxmind download API has a daily quota of requests.
Set to appropriate update interval.

Getting Started

// pseudo code
package main
import (
  "net"
  "github.com/gjbae1212/go-geoip2"
  
)

func main() {
   // db, err := Open("local-file-path")
   db, err := OpenURL("maxmind license key", "GeoLite2-Country", "/tmp",
      geoip2.WithUpdateInterval(6 * time.Hour), geoip2.WithRetries(2), geoip2.WithSuccessFunc(func(){}),...)
   if err != nil {
   	  panic(err)
   }
   
   ip := net.ParseIP("8.8.8.8")
   record, err := db.City(ip)
   if err != nil {
      panic(err)
   }
}

Inspiration

This project was inspired by oschwald/geoip2-golang

LICENSE

This project is following The MIT.

About

This project can search for IP information through Maxmind geoip2 databases. It supports to be automatically downloaded and updated the latest Maxmind databases in background.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published