View Source Antikythera.Controller.Plug (antikythera v0.5.1)
Macro definition for plug DSL.
"Plug" is a specification of composable modules for web apps. For example, you can define your authentication logic as a plug and apply it to all your controller actions.
Usage
To use plug you must first add use Antikythera.Controller
in your controller module.
Then you can invoke plug/3
macro as follows.
plug Antikythera.Plug.BasicAuthentication, :check_with_config, []
The arguments are
- module
- function name
- options to be passed to plug function
- (optional) options for enabling plug
In this case Antikythera.Plug.BasicAuthentication.check_with_config/2
is invoked just before execution of actions
defined in this controller module.
If you want to skip running plug for some actions in a controller module, you can use :except
or :only
option.
plug YourGear.SomePlug1, :do_something, [], [except: [:action_x, :action_y]]
plug YourGear.SomePlug2, :do_something, [], [only: [:action_x]]