Skip to content

febelery/go-apidoc

Repository files navigation

go-apidoc

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
})

依赖

About

通过访问接口上下文自动生成文档

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published