如何使用接受 multipart/form-data 的 goDoc 记录我的服务端点
How to document my service endpoint with goDoc that accepts multipart/form-data
我有一个用 Go/Gin 编写的服务,我接受 multipart/form-data 来接受用户的文件列表。代码如下所示。
func UploadScreenshotsHandler(c *gin.Context) {
//Multipart form
form, err := c.MultipartForm()
if err != nil {
logger.Log.Error(err.Error())
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
files := form.File
// more logics with the files
}
我正在使用 GoDoc 来记录我的端点。那么我该如何指定我的 godoc 以便 swagger 知道这是一个接受 multipart/form-data?
的端点
// UploadFileHandler godoc
// @Summary Upload a list of file
// @Description An API for clients to upload files
// @Param <WHAT DO I PUT HERE??> <----------
// @Success 200 "Successfully uploaded"
// @Failure 400 {object} interface{} "Bad request: request body has to be form-data"
// @Router / [post]
指定端点接收多个文件
// UploadFile godoc
// @Summary Uploads a file
// @Description Takes in a file as part of a multipart form and stores the file
// @Tags Uploads
// @Accept multipart/form-data
// @Produce json
// @Param file formData file true "File 1 to upload"
// @Param file1 formData file true "File 2 to upload"
// @Success 200 "Successfully uploaded"
// @Failure 400 {object} interface{} "Bad request: request body has to be form-data"
// @Router / [post]
func UploadHandler(c *gin.Context) {
...
}
我有一个用 Go/Gin 编写的服务,我接受 multipart/form-data 来接受用户的文件列表。代码如下所示。
func UploadScreenshotsHandler(c *gin.Context) {
//Multipart form
form, err := c.MultipartForm()
if err != nil {
logger.Log.Error(err.Error())
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
files := form.File
// more logics with the files
}
我正在使用 GoDoc 来记录我的端点。那么我该如何指定我的 godoc 以便 swagger 知道这是一个接受 multipart/form-data?
的端点// UploadFileHandler godoc
// @Summary Upload a list of file
// @Description An API for clients to upload files
// @Param <WHAT DO I PUT HERE??> <----------
// @Success 200 "Successfully uploaded"
// @Failure 400 {object} interface{} "Bad request: request body has to be form-data"
// @Router / [post]
指定端点接收多个文件
// UploadFile godoc
// @Summary Uploads a file
// @Description Takes in a file as part of a multipart form and stores the file
// @Tags Uploads
// @Accept multipart/form-data
// @Produce json
// @Param file formData file true "File 1 to upload"
// @Param file1 formData file true "File 2 to upload"
// @Success 200 "Successfully uploaded"
// @Failure 400 {object} interface{} "Bad request: request body has to be form-data"
// @Router / [post]
func UploadHandler(c *gin.Context) {
...
}