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 main

import (
    "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。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值