一.注解介绍
在gin-swagger中,对参数的注解主要包含如下几个:
// @Summary 摘要 // @Description 描述 // @Param 参数格式,从左到右分别为:参数名、入参类型、数据类型、是否必填、注释 ,其中入参类型包括header,query,path,body // @Success 响应成功,从左到右分别为:状态码、参数类型、数据类型、注释 // @Failure 响应失败,从左到右分别为:状态码、参数类型、数据类型、注释 // @Router 路由,从左到右分别为:路由地址,HTTP的方法
二.如何使用切片
使用切片主要有两种方法,一种使用body传输,一种使用query传输。
1.使用body方式
相关注解:
// @Param ids body []string false "env"
// @Router /svctest [post]
调用方式:
r,_:=c.GetRawData()
fmt.Println(string(r))
或者
buf:=make([]byte,2048)
n,_:=c.Request.Body.Read(buf)
fmt.Println(string(buf[0:n]))
2.使用query方式
相关注解:
// @Param ids query []string false "env"
// @Router /svctest [post]
调用方法:
e:=c.QueryArray("ids")
fmt.Println(e)