SuperPlug
Give your Plug superpowers!
Usage
defmodule FooPlug do
use SuperPlug
def init(opts) do
...
end
def call(conn, opts) do
...
end
endPrimary Superpower
call/1 initializes default options.
FooPlug.call(conn)
# FooPlug.call(conn, FooPlug.init([]))Secondary Superpower
call/2 initializes keyword options.
FooPlug.call(conn, bar?: true)
# FooPlug.call(conn, FooPlug.init(bar?: true))Tertiary Superpower
call/2 short circuits if an error is assigned.
conn = %{assigns: %{error: :not_found}}
^conn = FooPlug.call(conn)It can be configured to return the error as a tuple.
defmodule BarPlug do
use SuperPlug, return_error_as_tuple: true
...
end
conn = %{assigns: %{error: :not_found}}
{:error, :not_found, ^conn} = BarPlug.call(conn)Installation
def deps do
[
{:super_plug, "~> 1.1"}
]
end