欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

go Iris 使用swagger

发布时间:2023/12/20 编程问答 47 豆豆
生活随笔 收集整理的这篇文章主要介绍了 go Iris 使用swagger 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

1.先下载:swag 使用以下指令

go get -u github.com/swaggo/swag/cmd/swag

2.初始化

swag init

3.下载swagger lris所需文件

go get -u github.com/iris-contrib/swagger go get -u github.com/iris-contrib/swagger/swaggerFiles

4.在你的项目中引入他们

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的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。