Geolix v1.1.0 Geolix View Source

IP location lookup provider.

Usage

Fetching information for a single IP is done by passing it as a binary or tuple to Geolix.lookup/1:

iex> Geolix.lookup("127.0.0.1")
%{
  city: %{...},
  country: %{...}
}

The response will be a map with the :id of each configured database as the key and the database response as the value.

If you are only interested in the response of a specific database you can use Geolix.lookup/2:

iex> Geolix.lookup({127, 0, 0, 1}, where: :my_database)
%{...}

The result structured of each database is specific to the adapter used.

Lookup Options

There are two options you can pass to Geolix.lookup/2 to modify the lookup behaviour:

  • :timeout - GenServer call timeout for the lookup. Defaults to 5_000.
  • :where - Lookup information in a single registered database

The adapter used can require and/or understand additional options. To accommodate this the options are passed unmodified to the adapter's on lookup function.

Link to this section Summary

Functions

Loads a database according to its specification.

Looks up IP information.

Fetch metadata from one or multiple databases.

Reloads all configured databases in the background.

Unloads a database.

Link to this section Functions

Link to this function

load_database(database)

View Source
load_database(map()) :: :ok | {:error, term()}

Loads a database according to its specification.

Requires at least the fields :id and :adapter. Any other required fields depend on the adapter's requirements.

Link to this function

lookup(ip, opts \\ [])

View Source
lookup(ip :: :inet.ip_address() | binary(), opts :: Keyword.t()) :: map() | nil

Looks up IP information.

Link to this function

metadata(opts \\ [])

View Source
metadata(opts :: Keyword.t()) :: map() | nil

Fetch metadata from one or multiple databases.

Link to this function

reload_databases()

View Source
reload_databases() :: :ok

Reloads all configured databases in the background.

Link to this function

unload_database(id)

View Source
unload_database(atom()) :: :ok

Unloads a database.

This operation is lazy. The database will stay loaded but won't be reloaded or used for lookups.