Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Add instructions on setting up database cache directory in Elixir.
  • Loading branch information
petrus-jvrensburg authored Jul 25, 2024
1 parent 49ef423 commit 31d58cb
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,37 @@ ok = locus:start_loader(country, {maxmind, "GeoLite2-Country"}).
% implementing the locus_custom_fetcher behaviour.
```

Or, in Elixir, start the database loaders that you'll be using in `application.ex`:
In Elixir, you'll need to specify the cache directory explicitly when starting the database loaders. You can do that in `application.ex`:

```elixir
def start(_type, _args) do
# :locus.start_loader(:asn, {:maxmind, "GeoLite2-ASN"})
# :locus.start_loader(:country, {:maxmind, "GeoLite2-Country"})
:locus.start_loader(:city, {:maxmind, "GeoLite2-City"})
require Logger
...

def start(_type, _args) do
# only start the database loader process in environments where a license key is defined
if Application.get_env(:locus, :license_key) do
locus_cache_directory = "/tmp/locus/"

case File.mkdir(locus_cache_directory) do
:ok ->
Logger.info("New directory created for IP geolocation cache: #{locus_cache_directory}")

{:error, :eexist} ->
Logger.info("Loading IP geolocation cache from: #{locus_cache_directory}")
end

# :locus.start_loader(:asn, {:maxmind, "GeoLite2-ASN"},
# database_cache_file: Path.join([locus_cache_directory, "maxmind_asn.mmdb.gz"])
# )

# :locus.start_loader(:country, {:maxmind, "GeoLite2-Country"},
# database_cache_file: Path.join([locus_cache_directory, "maxmind_country.mmdb.gz"])
# )

:locus.start_loader(:city, {:maxmind, "GeoLite2-City"},
database_cache_file: Path.join([locus_cache_directory, "maxmind_city.mmdb.gz"])
)
end
...
```

Expand Down

0 comments on commit 31d58cb

Please sign in to comment.