cdn.go 736 B

123456789101112131415161718192021222324252627282930313233343536
  1. package controller
  2. import (
  3. "kng_feed_api/helper"
  4. "net/http"
  5. "os"
  6. "path/filepath"
  7. "github.com/gin-gonic/gin"
  8. )
  9. func SendFileToClient(context *gin.Context) {
  10. var fileName = filepath.Join(helper.RootDir(), "feed.xml")
  11. _, err := os.Stat(fileName)
  12. if err != nil {
  13. if os.IsNotExist(err) {
  14. context.JSON(http.StatusInternalServerError,
  15. gin.H{
  16. "description": "The file does not exist yet. Contact the administrator.",
  17. "err": "ERR-001",
  18. },
  19. )
  20. return
  21. } else {
  22. context.JSON(http.StatusInternalServerError,
  23. gin.H{
  24. "description": err.Error(),
  25. "err": "unknown error",
  26. },
  27. )
  28. return
  29. }
  30. }
  31. context.FileAttachment(fileName, "feed.xml")
  32. context.Status(http.StatusOK)
  33. }