FileStore.Config (file_store v0.3.0) View Source

Define a configurable store.

Usage

First, define a new module:

defmodule MyApp.Storage do
  use FileStore.Config, otp_app: :my_app
end

In your config files, you'll need to configure your adapter:

config :my_app, MyApp.Storage,
  adapter: FileStore.Adapters.Disk,
  storage_path: "/path/to/files",
  base_url: "https://localhost:4000"

You can also configure any FileStore.Middleware here:

config :my_app, MyApp.Storage,
  adapter: FileStore.Adapters.Disk,
  # ...etc...
  middleware: [FileStore.Middleware.Errors]

If you need to dynamically configure your store at runtime, you can implement the init/1 callback.

def init(opts) do
  Keyword.put(opts, :foo, "bar")
end

Example

iex> MyApp.Storage.write("foo", "hello world")
:ok

iex> MyApp.Storage.read("foo")
{:ok, "hello world"}