Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/febelery/go-apidoc
通过访问接口上下文自动生成文档
https://github.com/febelery/go-apidoc
api apidoc auto docs document go node
Last synced: 5 days ago
JSON representation
通过访问接口上下文自动生成文档
- Host: GitHub
- URL: https://github.com/febelery/go-apidoc
- Owner: febelery
- Created: 2023-11-10T13:57:25.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-31T08:12:17.000Z (10 months ago)
- Last Synced: 2024-01-31T09:32:22.354Z (10 months ago)
- Topics: api, apidoc, auto, docs, document, go, node
- Language: Go
- Homepage:
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go-apidoc
API 文档生成
该项目使用 `apidoc` 工具自动生成 API 文档。通过自动抓取在 Go 语言的 API 接口上下文生成符合 `apidoc`
要求的文档。## 安装
```shell
go get -u github.com/febelery/go-apidoc
npm install -g apidoc
```## 使用
- gofiber 框架
```golang
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