An IP2Location binary data query engine that only works with the DB1 (Country) database.
There are a few major differences between this and the official library, ip2location/ip2location-go:
- It only supports the DB1 (Country) database;
- Every function can return an error;
- No print statements;
- It's faster and consumes less memory.
go get -u github.com/tserkov/ip2loc
It's all in the godoc.
import "github.com/tserkov/ip2loc"
db, err := ip2loc.New("/path/to/db.bin")
if err != nil {
// handle it
}
defer db.Close()
result, err := db.Query("8.8.8.8")
if err != nil {
// handle it
}
fmt.Printf(
"Country Code: %s\nCountry Name: %s\n",
result.CountryCode,
result.CountryName,
)
If you happen to be on Linux, this repository contains an executable that accepts space-delimited IPs via arguments or stdin and spits out results in {IP} {Country Name} ({Country Code})
format to stdout.
It does require that the environment variable IP2LOC_DB
be set to the path to the ip2location db1 bin.
The super permissive MIT License.
While I don't plan on supporting databases beyond DB1, I will gladly take any performance-enhancing contributions.