Runlight.Geo (runlight v0.1.0)

Copy Markdown View Source

Where a visitor is, from a hosting platform's headers or a database lookup.

A location is %{country: "CA", region: "CA-ON", city: "Toronto"}: the country ISO 3166-1 alpha-2 in upper case, the region ISO 3166-2. The instance's :geo option is a lookup, a function of the client's address that answers a map with any of those keys or nil, such as one file_lookup/1 makes from an MMDB file (MaxMind's GeoLite2 City, or DB-IP's free city database). Headers from Vercel, Cloudflare, or Netlify always win over it.

Summary

Functions

A city as people say it, without a trailing bracketed district.

A lookup from an MMDB file the owner supplies, read into memory once.

A lookup answering from an MMDB reader. DB-IP's records follow MaxMind's city layout, with names but no subdivision codes; a city loses the district DB-IP adds in brackets, as in "Toronto (Old Toronto)".

Functions

city_name(name)

@spec city_name(String.t()) :: String.t()

A city as people say it, without a trailing bracketed district.

file_lookup(path)

@spec file_lookup(Path.t()) :: (String.t() -> map() | nil)

A lookup from an MMDB file the owner supplies, read into memory once.

lookup_from(reader)

@spec lookup_from(Runlight.Mmdb.t()) :: (String.t() -> map() | nil)

A lookup answering from an MMDB reader. DB-IP's records follow MaxMind's city layout, with names but no subdivision codes; a city loses the district DB-IP adds in brackets, as in "Toronto (Old Toronto)".