Use different package for geoip

This commit is contained in:
2021-04-10 12:12:08 +02:00
parent a5b344277c
commit 3eaa7d2397
3 changed files with 12 additions and 7 deletions

View File

@@ -4,23 +4,29 @@ import (
_ "embed"
"net"
"github.com/oschwald/geoip2-golang"
"github.com/oschwald/maxminddb-golang"
)
//go:embed Geoacumen-Country.mmdb
var mmdb []byte
func (s *HoneypotServer) LookupCountry(ip net.IP) string {
db, err := geoip2.FromBytes(mmdb)
db, err := maxminddb.FromBytes(mmdb)
if err != nil {
s.Logger.Warnw("Error opening geoip database", "error", err)
return "??"
}
country, err := db.Country(ip)
var record struct {
Country struct {
ISOCode string `maxminddb:"iso_code"`
} `maxminddb:"country"`
}
err = db.Lookup(ip, &record)
if err != nil {
s.Logger.Warnw("Error doing geoip lookup", "error", err)
return "??"
}
return country.Country.IsoCode
return record.Country.ISOCode
}