upload.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package v1
  2. import (
  3. "fmt"
  4. "git.getensh.com/common/gopkgs/logger"
  5. "git.getensh.com/common/gopkgs/tasker/httptasker"
  6. "git.getensh.com/common/gopkgs/util"
  7. "github.com/gin-gonic/gin"
  8. "go.uber.org/zap"
  9. "xingjia-official-gateway/errors"
  10. param_v1 "xingjia-official-gateway/param/v1"
  11. "xingjia-official-gateway/parser"
  12. )
  13. //
  14. // @Summary 获取文件
  15. // @Description 获取文件
  16. // @Tags download
  17. // @Accept json
  18. // @Produce json
  19. // @Param token header string true "jwt token"
  20. // @Param obj query string true " "
  21. // @Success 200 {object} v1.UploadResponse
  22. // @Failure 500 {object} base.HTTPError
  23. // @Router /api/v1/file [get]
  24. func (c Controller) DownLoad(ctx *gin.Context) {
  25. // 解析参数
  26. req := param_v1.DownLoadRequest{}
  27. parseParamTask := func() error {
  28. err := util.ShouldBind(ctx, nil, nil, &req.DownLoadQuery, nil)
  29. if err != nil {
  30. fmt.Printf("upload get file:%v\n", err)
  31. logger.Error("func",
  32. zap.String("call", "ctx.FormFile"),
  33. zap.String("error", err.Error()))
  34. return errors.SystemError
  35. }
  36. ctx.File(parser.Conf.ObjPath + req.Obj)
  37. return nil
  38. }
  39. httptasker.Exec(ctx, parseParamTask)
  40. }