defmodule Plug.GeoIP2 do @moduledoc """ Adds geo location to a Plug connection based upon the client IP address by using MaxMind's GeoIP2 database. To use it, just plug it into the desired module. The lookup uses the remote_ip field of the connection. plug Plug.GeoIP2, as: :raw, where: :city ## Options * `:as` - Return the result as a `:struct` or `:raw` (plain map) * `:locale` - Language (atom) to fetch information for. Only affects "top level" struct values. * `:where` - Lookup information in a single registered database """ @doc "Callback implementation for Plug.init/1" def init(options) do options end @doc "Callback implementation for Plug.call/2" def call(conn, options) do conn |> Plug.Conn.assign(:geolocation, Geolix.lookup(conn.remote_ip, options)) end end