Skip to content

ulule/geoipfix

Repository files navigation

geoipfix =====

geoipfix is a Go service (HTTP+RPC) to retrieve geolocation information about an ip address with freegeoip helpers.

We are using bindings from the maxmind database.

Installation

Build it locally

  1. Make sure you have a Go language compiler >= 1.3 (required) and git installed.
  2. Make sure you have the following go system dependencies in your $PATH: bzr, svn, hg, git
  3. Ensure your GOPATH is properly set.
  4. Download it:
git clone https://github.com/ulule/geoipfix.git
  1. Run make build

You have now a binary version of geoipfix in the bin directory which fits perfectly with your architecture.

Build it using Docker

If you don't want to install Go and Docker is installed on your computer

make docker-build

You will have a binary version of geoipfix compiled for linux in the bin directory.

Configuration

Configuration should be stored in a readable file and in JSON format.

A complete example of the configuration file with RPC+HTTP would be:

config.json

{
    "server": {
        "rpc": {
            "port": 33001
        },
        "http": {
            "port": 3001,
            "cors": {
                "allowed_origins": ["*.ulule.com"],
                "allowed_methods": ["GET", "HEAD", "POST"],
                "allowed_headers": ["Origin", "Accept", "Content-Type", "X-Requested-With"]
            }
        }
    },
    "database_path": "./GeoLite2-City.mmdb.gz"
}

Be careful, you should download first locally the GeoLite database because the service will be unavailable until it will download the database.

HTTP server

The HTTP server is based on chi.

It's disabled by default, you can activate it by adding the http section to server.

config.json

{
    "server": {
        "http": {
            "port": 3001,
        }
    }
}

CORS

geoipfix supports CORS headers customization in your config file.

To enable this feature, set allowed_origins and allowed_methods, for example:

config.json

{
  "allowed_origins": ["*.ulule.com"],
  "allowed_methods": ["GET", "HEAD"]
}

RPC server

The RPC server is based on grpc.

It's disabled by default, you can activate it by adding the rpc section to server.

config.json

{
    "server": {
        "http": {
            "port": 33001,
        }
    }
}

You can found a client example in the repository and execute it:

go run examples/client/main.go -ip {YOUR_IP_ADDRESS} -server-addr {RPC_ADDRESS}

Usage

When your configuration is done, you can start the service as follow:

geoipfix -c config.json

or using an environment variable:

GEOIPFIX_CONF=/path/to/config.json geoipfix

By default, this will run the application on port 3001 and can be accessed by visiting:

http://localhost:3001

The port number can be configured with port option in your config file.

To see a list of all available options, run:

geoipfix --help

Development

I recommend to install the live reload utility modd to make your life easier.

Install it:

go get github.com/cortesi/modd/cmd/modd

Then launch it in the geoipfix directory:

GEOIPFIX_CONF=config.json make live

Dang, what's this name?

It was an initial proposal from kyojin based on Idéfix.

image