phoenix项目中的router.ex中的“管道”的定义在哪里?
我正在通过VScode阅读Phoenix项目。 pipeline
,范围
在router.ex.ex
文件中的含义是什么。
无法通过vscode
找到参考。它缝制它们不是精灵语言的关键字。他们是什么?
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, {HelloWeb.LayoutView, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
plug HelloWeb.Plugs.Locale, "en"
end
pipeline :api do
plug :accepts, ["json"]
end
scope "/", HelloWeb do
pipe_through :browser
get "/", PageController, :index
get "/hello", HelloController, :index
get "/hello/:messenger", HelloController, :show
end
I am reading phoenix project through vscode. What's the meaning of pipeline
,scope
in the router.ex
file.
It can't be found reference by vscode
. It seams that they are not keywords of elixir language. What's are they?
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, {HelloWeb.LayoutView, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
plug HelloWeb.Plugs.Locale, "en"
end
pipeline :api do
plug :accepts, ["json"]
end
scope "/", HelloWeb do
pipe_through :browser
get "/", PageController, :index
get "/hello", HelloController, :index
get "/hello/:messenger", HelloController, :show
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们是宏:在汇编过程中,他们将评估并创建常规代码(即宏是“创建代码的代码”)。宏可以帮助您定义简单的接口并迅速生成许多乏味的代码,但是它们绝对难以调试和关注编辑器。
在这种情况下,这些宏可以方便地定义特定域的语言(DSL),该语言提供了一种表达方式来定义路由和中间件。
可以在您的任何代码或依赖项中定义宏。查找
defmacro
关键字。在这种情况下,它们在Phoenix路由器
模块中定义。They are macros: during compilation they will evaluate and create regular code (i.e. macros are "code that creates code"). Macros can help you define simple interfaces and quickly generate lots of tedious code, but they are definitely more difficult to debug and follow in an editor.
In this case, these macros are handy for defining a domain specific language (DSL) that offers an expressive way to define routes and middleware.
Macros can be defined in any of your code or in your dependencies. Look for the
defmacro
keyword. In this case, they're defined within the PhoenixRouter
module.