<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>swagger on 华说记录我的生活</title>
    <link>http://www.huasay.com/tags/swagger/</link>
    <description>Recent content in swagger on 华说记录我的生活</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>zh</language>
    <lastBuildDate>Sun, 27 Aug 2023 21:20:10 +0800</lastBuildDate>
    <atom:link href="http://www.huasay.com/tags/swagger/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>swagger的使用</title>
      <link>http://www.huasay.com/2023/08/27/swagger_usage/</link>
      <pubDate>Sun, 27 Aug 2023 21:20:10 +0800</pubDate>
      <guid>http://www.huasay.com/2023/08/27/swagger_usage/</guid>
      <description>随着RESTful API的流行，Swagger已经成为了一种通用的API描述和文档格式。它可以帮助开发者描述、测试和文档化RESTful API。在本文中，我们将介绍在go中如何使用相应的库生成swagger文档。在golang中, 有两款可以生成swagger的库，一般我们选择https://github.com/swaggo/swag,还有另一款https://github.com/go-swagger/go-swagger,相对来说，使用起来swag更易用一点
安装 1 go install github.com/swaggo/swag/cmd/swag@latest 默认情况下，会安装在go path相关的目录下，该目录一般已经加入环境变量，若没有加入环境变量，我们可根据每种系统的不同，手动加入至环境变量中
检测是否安装成功：
1 swag -v 返回具体的版本号即成功:
1 swag.exe version v1.8.12 使用 路由绑定 我们使用的是gin框架，swag对gin也有集成封装, 我们可以在gin的路由绑定至对应的swagger文档
1 2 3 // swagger文档查看路径 url := ginSwagger.URL(&amp;#34;/swagger/doc.json&amp;#34;) // The url pointing to API definition r.GET(&amp;#34;swagger/*any&amp;#34;, ginSwagger.WrapHandler(swaggerFiles.Handler, url)) 依赖库：
1 2 swaggerFiles &amp;#34;github.com/swaggo/files&amp;#34; &amp;#34;github.com/swaggo/gin-swagger&amp;#34; 路由注释 1 2 3 4 5 6 7 8 9 10 // ListUser // @Summary 查询用户信息 // @Tags 用户 // @Description	查询用户信息 // @Produce	json // @Param UserId header string true &amp;#34;当前用户id&amp;#34; // @Param query query dto.</description>
    </item>
  </channel>
</rss>
