go Iris 使用swagger
生活随笔
收集整理的這篇文章主要介紹了
go Iris 使用swagger
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.先下載:swag 使用以下指令
go get -u github.com/swaggo/swag/cmd/swag2.初始化
swag init3.下載swagger lris所需文件
go get -u github.com/iris-contrib/swagger go get -u github.com/iris-contrib/swagger/swaggerFiles4.在你的項目中引入他們
package mainimport ("github.com/kataras/iris""github.com/iris-contrib/swagger""github.com/iris-contrib/swagger/swaggerFiles"_ "./docs" // docs is generated by Swag CLI, you have to import it. )// @title Swagger Example API // @version 1.0 // @description This is a sample server Petstore server. // @termsOfService http://swagger.io/terms/// @contact.name API Support // @contact.url http://www.swagger.io/support // @contact.email support@swagger.io// @license.name Apache 2.0 // @license.url http://www.apache.org/licenses/LICENSE-2.0.html// @host petstore.swagger.io // @BasePath /v2 func main() {app := iris.New()config := &swagger.Config{URL: "http://localhost:8080/swagger/doc.json", //The url pointing to API definition}// use swagger middleware to app.Get("/swagger/{any:path}", swagger.CustomWrapHandler(config, swaggerFiles.Handler))app.Run(iris.Addr(":8080")) }5.執行go run 然后去瀏覽器訪問
http://localhost:8080/swagger/index.html
6.根據文檔編寫接口文檔http://editor.swagger.io/#/
依據https://github.com/iris-contrib/swagger。
總結
以上是生活随笔為你收集整理的go Iris 使用swagger的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于启动报错:Field xxxMapp
- 下一篇: 计算机应用基础 随堂问答,【计算机应用基