mirror of
https://github.com/skidoodle/ipinfo.git
synced 2025-02-15 08:29:17 +01:00
maxmind
This commit is contained in:
parent
9240ecbf98
commit
0d760f38ae
8 changed files with 394 additions and 431 deletions
35
db.go
Normal file
35
db.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"sync"
|
||||
|
||||
"github.com/oschwald/maxminddb-golang"
|
||||
)
|
||||
|
||||
var cityDB *maxminddb.Reader
|
||||
var asnDB *maxminddb.Reader
|
||||
var dbMtx = new(sync.RWMutex)
|
||||
|
||||
const (
|
||||
cityDBPath = "./GeoLite2-City.mmdb"
|
||||
asnDBPath = "./GeoLite2-ASN.mmdb"
|
||||
)
|
||||
|
||||
func initDatabases() {
|
||||
var err error
|
||||
|
||||
cityDB, err = maxminddb.Open(cityDBPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Error opening city database: %v", err)
|
||||
}
|
||||
|
||||
asnDB, err = maxminddb.Open(asnDBPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Error opening ASN database: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func startUpdater() {
|
||||
log.Println("MaxMind GeoIP databases will be updated by geoipupdate automatically.")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue