接口文檔使用?swagger
?,只要你在寫代碼的時(shí)候,稍加幾個(gè)注解,文檔自動(dòng)生成。
使用前提:先安裝?swag
?
?go install github.com/swaggo/swag/cmd/swag
? 會(huì)在?gopath
?的?bin
?目錄下生成?swag
?可執(zhí)行文件,確保?bin
?目錄已設(shè)置環(huán)境變量可全局執(zhí)行。
package main
import (
_ "gfast/boot"
_ "gfast/router"
"github.com/gogf/gf/frame/g"
)
// @title gfast
// @version 2.0
// @description gfast 在線API文檔
// @host localhost:8200
// @BasePath /
func main() {
}
// @Summary 信息列表
// @Description 信息列表
// @Tags 文章管理
// @Param data body cms_news.ReqListSearchParams true "data"
// @Success 0 {object} library.Response "{"code": 200, "data": [...]}"
// @Router /system/cms/news/list [get]
// @Security
func (c *CmsNews) List(r *ghttp.Request) {
...
在 ?./
? 項(xiàng)目根目錄下(和main.go文件同級(jí)目錄下)執(zhí)行:?gf swagger --pack
? 生成或更新api文檔。
執(zhí)行后在項(xiàng)目根目錄會(huì)自動(dòng)生成swagger文件夾,其中保存了接口文檔數(shù)據(jù)?swagger.json
?
swaggo 詳細(xì)文檔地址請(qǐng)查閱:https://github.com/swaggo/swag
goframe gf工具使用: https://goframe.org/pages/viewpage.action?pageId=1115794
更多建議: