geoip-service
A fast Go-Micro based microservice for looking up MaxMind GeoIP2 and GeoLite2 database.
Prerequisites
Requires a go installation.
A Database (choose one):
Running the service
This service works as Go-Micro microservice. You may want to
setup your own registry with MICRO_REGISTRY
/MICRO_REGISTRY_ADDRESS
or use other go-micro flags.
Download it
go get github.com/paysuper/geoip-service
If you need it uou can rebuild proto file with protoc
protoc --proto_path=. --micro_out=. --go_out=. geoip.proto
Setup environment variable MAXMIND_GEOIP_DB_PATH
with path to the maxmind database path.
The path can be local file path like /application/assets/GeoLite2-City.mmdb
,
or it can be AWS S3 object path like s3://bucketName/GeoLite2-City.mmdb
. In the latter case it is required to provide S3 access credentials with the environment variables AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
.
By default service will be executed with declared by MICRO_REGISTRY
registry and GRPC as a transport.
Using Docker
The docker file in this project used to launch geoip-service in Protocol One environment. You may change it in any
way you need it.
Using the service
Once the service is running you can use go-micro to make requests
package main
import (
"context"
"fmt"
"github.com/paysuper/geoip-service/pkg"
"github.com/paysuper/geoip-service/pkg/proto"
"github.com/micro/go-micro"
)
func main() {
// create a new service
service := micro.NewService()
// parse command line flags
service.Init()
// Create new greeter client
client := proto.NewGeoIpService(geoip.ServiceName, service.Client())
// Call it
rsp, err := client.GetIpData(context.TODO(), &proto.GeoIpDataRequest{IP: "8.8.8.8"})
if err != nil {
fmt.Println(err)
}
// Print response
fmt.Println(rsp)
}