Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plug.Router macros and functional plugs #1237

Open
jspri opened this issue Jun 30, 2024 · 2 comments · May be fixed by #1245
Open

Plug.Router macros and functional plugs #1237

jspri opened this issue Jun 30, 2024 · 2 comments · May be fixed by #1245

Comments

@jspri
Copy link

jspri commented Jun 30, 2024

I'm super new to elixir, so forgive me if the below doesn't make sense.

If I attempt to use a functional plug with the router macros e.g. match I get the error ** (UndefinedFunctionError) function :foo.init/1 is undefined (module :foo is not available). I'm pretty sure the issue is not with my plug, as it works when using the regular plug macro e.g. plug :foo.

Minimal reproduction below

defmodule Router do
  use Plug.Router

  plug :match
  plug :dispatch

  @spec foo(Plug.Conn.t(), any()) :: Plug.Conn.t()
  def foo(conn, _opts) do
    conn
  end

  match _, to: :foo
end

If I'm not making any errors then please consider this a feature request - The functional plugs are much more simple/concise, so it would be great to be able to use them in more places, if not everywhere, just for the sake of consistency.

@josevalim
Copy link
Member

You are right, the :to syntax supports only module plugs at the moment. We could indeed support it here.

@johnmcguin johnmcguin linked a pull request Sep 5, 2024 that will close this issue
@johnmcguin
Copy link

johnmcguin commented Sep 5, 2024

Hi hi, thanks for Plug and Elixir 😎! Trying my hand at this in #1245

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants