go swag常用注释
生成在线文档校验接口时,主要使用这个@Param这种注解写对。个人理解,这些注释不是对代码功能的约束,而是对生成的前端测试ui中前端代码的约束。或者说对文档的约束
param的格式:
param name
,param type
,data type
,is mandatory?
,comment
attribute(optional)
@Param enumstring query string false "string enums" Enums(A, B, C)
Param Type
- query
- path
- header
- body
- formData
Data Type
- string (string)
- integer (int, uint, uint32, uint64)
- number (float32)
- boolean (bool)
- user defined struct
Mime Types
主要在@accept【前端需要传哪个】、@produce【自己传给前端的是哪种】中使用
Alias | MIME Type |
---|---|
json | application/json |
xml | text/xml |
plain | text/plain |
html | text/html |
mpfd | multipart/form-data |
x-www-form-urlencoded | application/x-www-form-urlencoded |
json-api | application/vnd.api+json |
json-stream | application/x-json-stream |
octet-stream | application/octet-stream |
png | image/png |
jpeg | image/jpeg |
gif | image/gif |
值的数据约束
Field Name | Type | Description |
---|---|---|
validate |
string
|
Determines the validation for the parameter. Possible values are: required .
|
default | * |
Declares the value of the parameter that the server will use if none is provided, for example a “count” to control the number of results per page might default to 100 if not supplied by the client in the request. (Note: “default” has no meaning for required parameters.) See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.2. Unlike JSON Schema this value MUST conform to the defined type for this parameter.
|
maximum |
number
|
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.2. |
minimum |
number
|
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.1.3. |
maxLength |
integer
|
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.1. |
minLength |
integer
|
See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.2.2. |
enums | [*] | See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.5.1. |
format |
string
|
The extending format for the previously mentioned type . See Data Type Formats for further details.
|
collectionFormat |
string
|
Determines the format of the array if type array is used. Possible values are:csv - comma separated values foo,bar .ssv - space separated values foo bar .tsv - tab separated values foo\tbar .pipes - pipe separated values foo|bar .multi - corresponds to multiple parameter instances instead of multiple values for a single instance foo=bar&foo=baz . This is valid only for parameters in “query” or “formData”.Default value is csv .
|
// ShowAccount godoc
// @Summary Show a account
// @Description get string by ID
// @ID get-string-by-int
// @Accept json
// @Produce json
// @Param id path int true "Account ID"
// @Success 200 {object} model.Account
// @Header 200 {string} Token "qwerty"
// @Failure 400,404 {object} httputil.HTTPError
// @Failure 500 {object} httputil.HTTPError
// @Failure default {object} httputil.DefaultError
// @Router /accounts/{id} [get]
func (c *Controller) ShowAccount(ctx *gin.Context) {id := ctx.Param("id")aid, err := strconv.Atoi(id)if err != nil {httputil.NewError(ctx, http.StatusBadRequest, err)return}account, err := model.AccountOne(aid)if err != nil {httputil.NewError(ctx, http.StatusNotFound, err)return}ctx.JSON(http.StatusOK, account)
}// ListAccounts godoc
// @Summary List accounts
// @Description get accounts
// @Accept json
// @Produce json
// @Param q query string false "name search by q"
// @Success 200 {array} model.Account
// @Header 200 {string} Token "qwerty"
// @Failure 400,404 {object} httputil.HTTPError
// @Failure 500 {object} httputil.HTTPError
// @Failure default {object} httputil.DefaultError
// @Router /accounts [get]
func (c *Controller) ListAccounts(ctx *gin.Context) {q := ctx.Request.URL.Query().Get("q")accounts, err := model.AccountsAll(q)if err != nil {httputil.NewError(ctx, http.StatusNotFound, err)return}ctx.JSON(http.StatusOK, accounts)
}
官方文档:
https://github.com/swaggo/swag#mime-types
go swag常用注释相关推荐
- 黑马程序员视频教程学习mybatis框架常用注释SQL语句学习笔记?
mybatis学习笔记 常用注释增删改查SQL语句 常用注释拓展SQL语句 解决实体类属性和数据库表中的属性名称不相同的问题: mybatis注解之一对一查询: mybatis注解之一对多查询: my ...
- JSDoc的常用注释规范
JSDoc的常用注释规范 JSDoc本质是代码注释 官网--https://jsdoc.zcopy.site/ 手册网API--https://www.shouce.ren/api/view/a/13 ...
- Mathematica 训练课(12)常用注释方法
为了在后期重新梳理和修改程序时,如果没有注释的代码那将很难阅读的代码,因此我们要合理的添加注释. 一.普通注释 (1)在mathematica添加注释我们一般会使用(**),效果如下图所示: 直接输入 ...
- java常用注释注解
1.@author 用于表示创建编辑这个类或者方法的作者. 用法:@author Rex表明作者是Rex 2.@see 其指向包.类.方法.属性,可以在注释中实现链接跳转. 用法:@see packa ...
- Swagger2 常用注释注解使用说明【总结】
一.在swagger-ui.html页面Models模块中显示实体类信息: //只要我们的接口中,返回值中存在实体类,他就会被扫描到 swagger中 @PostMapping(value=" ...
- mysql常用注释符_为MYSQL加注释mysql注释符
mysql 服务器支持 # 到该行结束.-- 到该行结束 以及 /* 行中间或多个行 */ 的注释方格: mysql> SELECT 1+1; # 这个注释直到该行结束 mysql> ...
- 【Qt】QtCreator中自动补全注释
1.简述 在QtCreator中编辑代码,可以自动补全函数注释,供doxygen使用并生成文档.doxygen的使用方法,后续会写一个详细的博文. 2.使用方法 在函数前分别输入"/**&q ...
- 黑客常用SQL注入绕过技术总结!
今天给大家再次分享一篇硬核内容,那就是黑客常用的SQL注入绕过技术,还是那句话:我们学渗透技术不是为了攻击别人的系统,而是了解黑客常用的渗透技能,以此来修复我们自己系统中的漏洞,使我们的系统更加健壮, ...
- 使用.NET中的XML注释(一) -- XML注释标签讲解
使用.NET中的XML注释(一) -- XML注释标签讲解 作者:Xt Idt 来源:博客园 发布时间:2011-04-02 11:46 阅读:9 次 原文链接 [收藏] 一.摘要 . ...
最新文章
- freemarker中运算符_如何在Web应用系统表示层开发中应用Velocity模板技术
- SpringMVC Restful api接口实现
- 嵌入式Web Service gSOAP的移植与应用(二)
- [CSS] Target Positional Elements Using *-Of-Type CSS pseudo-classes
- PHP基础学习之数组使用要点
- 知识点:图说 Mysql 权限管理
- WinSCP 连接 Ubuntu 拒绝的问题
- vue子组件mounted不执行_vue中父子组件传值,解决钩子函数mounted只运行一次的问题...
- 表格闪退怎么解决_win10中excel2013闪退怎么修复_win10中excel2013闪退如何解决
- 视频怎么转换html代码实现,音视频格式转换神器与html视频元素加字幕——零基础自学网页制作...
- 【Python】一键爬取金庸连载版/三联版/世纪新修版小说
- 图解MongoDB数据库学习路线指南
- cachecloud部署和创建机器
- html文件默认浏览器改不了,怎么设置默认浏览器 3种更改默认浏览器方法
- Windows10 如何禁用或删除大的Hiberfil.sys和Pagefile.sys文件
- sessionStorage和localStorage
- LF-YOLO: A Lighter and Faster YOLO for Weld Defect Detection of X-ray Image
- Android 自定义相机黑屏
- 蓝桥杯 算法训练 ALGO-932低阶行列式计算 python解法
- 导带电子浓度和价带空穴浓度