You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.0 KiB

  1. package v1
  2. import (
  3. "fmt"
  4. "gin-vue-admin/global/response"
  5. "gin-vue-admin/model"
  6. "github.com/gin-gonic/gin"
  7. "os"
  8. )
  9. // @Tags SysApi
  10. // @Summary 自动代码模板
  11. // @Security ApiKeyAuth
  12. // @accept application/json
  13. // @Produce application/json
  14. // @Param data body autoCodeModel.AutoCodeStruct true "创建自动代码"
  15. // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
  16. // @Router /autoCode/createTemp [post]
  17. func CreateTemp(c *gin.Context) {
  18. var a model.AutoCodeStruct
  19. _ = c.ShouldBindJSON(&a)
  20. err := a.CreateTemp()
  21. if err != nil {
  22. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("创建失败,%v", err), c)
  23. os.Remove("./ginvueadmin.zip")
  24. } else {
  25. c.Writer.Header().Add("Content-Disposition", fmt.Sprintf("attachment; filename=%s", "ginvueadmin.zip")) //fmt.Sprintf("attachment; filename=%s", filename)对下载的文件重命名
  26. c.Writer.Header().Add("Content-Type", "application/json")
  27. c.Writer.Header().Add("success", "true")
  28. c.File("./ginvueadmin.zip")
  29. os.Remove("./ginvueadmin.zip")
  30. }
  31. }