API 文档生成
该项目使用 apidoc
工具自动生成 API 文档。通过自动抓取在 Go 语言的 API 接口上下文生成符合 apidoc
要求的文档。
go get -u github.com/febelery/go-apidoc
npm install -g apidoc
- gofiber 框架
app.Static("/doc", "doc/api")
app.Static("/assets", "doc/api/assets")
app.Use(func(c *fiber.Ctx) error {
err := c.Next()
skip := string(c.Response().Header.Peek("Content-Type")) != "application/json" ||
strings.ToLower(os.Getenv("SKIP_DOC")) == "true"
headers := make(map[string]string)
if auth := c.GetReqHeaders()["Authorization"]; len(auth) > 0 {
headers["Authorization"] = auth[0]
}
go goapidoc.New(goapidoc.ApiDef{
Method: c.Method(),
Path: c.Route().Path,
Params: c.AllParams(),
Headers: headers,
Queries: c.Queries(),
StatusCode: c.Response().StatusCode(),
ResponseBody: c.Response().Body(),
Skip: skip,
})
return err
})
- Go >= 1.21
- Node.js
- apidoc:https://github.com/apidoc/apidoc