> For the complete documentation index, see [llms.txt](https://go-macaron.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://go-macaron.com/zh-cn/middlewares.md).

# 中间件和辅助模块

中间件及辅助模块允许您轻易地对模块的进行接入到您的 Macaron 应用中。

现在已经有许多 [中间件和辅助模块](https://github.com/go-macaron) 来简化您的工作：

* [auth](https://github.com/go-macaron/auth) - HTTP 基本认证
* [authz](https://github.com/go-macaron/authz) - ACL、RBAC 和 ABAC 的权限管理，基于 [Casbin](https://github.com/casbin/casbin)
* [bindata](/zh-cn/middlewares/bindata.md) - 嵌入二进制数据作为静态资源和模板文件
* [binding](/zh-cn/middlewares/binding.md) - 请求数据绑定和校验
* [cache](/zh-cn/middlewares/cache.md) - Cache 管理器
* [captcha](/zh-cn/middlewares/captcha.md) - 验证码服务
* [csrf](/zh-cn/middlewares/csrf.md) - 生成和验证 CSRF 令牌
* [gzip](/zh-cn/middlewares/gzip.md) - Gzip 压缩所有响应
* [i18n](/zh-cn/middlewares/i18n.md) - 国际化与本地化
* [inject](https://github.com/go-macaron/inject) - 映射和注入依赖
* [jade](https://github.com/go-macaron/jade) - Jade 模板引擎
* [method](https://github.com/go-macaron/method) - HTTP 方法覆盖
* [oauth2](https://github.com/go-macaron/oauth2) - OAuth 2.0 后端客户端
* [permissions2](https://github.com/xyproto/permissions2) - Cookies、多用户和权限管理
* [pongo2](https://github.com/go-macaron/pongo2) - Pongo2 模板引擎
* [renders](https://github.com/go-macaron/renders) - 类 Beego 模板引擎（Macaron 已有内置模板引擎，此为可选）
* [session](/zh-cn/middlewares/session.md) - Session 管理器
* [sockets](https://github.com/go-macaron/sockets) - WebSockets 管道绑定
* [switcher](/zh-cn/middlewares/switcher.md) - 多站点支持
* [toolbox](https://github.com/go-macaron/toolbox) - 健康检查、性能调试和路由统计等服务

## 注册中间件的最佳顺序

有些中间件会依赖其它中间件，以下为最佳的注册顺序列表：

1. `macaron.Logger()`
2. `macaron.Recovery()`
3. `gzip.Gziper()`
4. `macaron.Static()`
5. `macaron.Renderer()`/`pongo2.Pongoer()`
6. `i18n.I18n()`
7. `cache.Cacher()`
8. `captcha.Captchaer()`
9. `session.Sessioner()`
10. `csrf.Csrfer()`
11. `toolbox.Toolboxer()`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://go-macaron.com/zh-cn/middlewares.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
