Building the router DSL
In order for the use Goldcrest.Router, ...
statement to work, we will first need to define a __using__/1
macro in the Goldcrest.Router
module. This macro will be responsible for injecting all the router behavior into a module.
Let’s start by simply moving all the plug
calls and private parse_body
and decode_body_params
functions to the __using__/1
macro:
defmodule Goldcrest.Router do import Plug.Conn defmacro __using__(opts) do quote do use Plug.Router @opts unquote(opts) plug Plug.Parsers, parsers: [:urlencoded, :multipart], pass: ["text/html", "application/*"] plug :parse_body plug :match ...