cdn.go 909 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 SendXmlFeedToClient(context *gin.Context) {
  10. sendFile(context, "feed.xml")
  11. }
  12. func SendCsvDeltaToClient(context *gin.Context) {
  13. sendFile(context, "delta.csv")
  14. }
  15. func sendFile(context *gin.Context, fileMark string) {
  16. var fileName = filepath.Join(helper.RootDir(), fileMark)
  17. _, err := os.Stat(fileName)
  18. if err != nil {
  19. if os.IsNotExist(err) {
  20. context.JSON(http.StatusInternalServerError,
  21. gin.H{
  22. "description": "The file does not exist yet. Contact the administrator.",
  23. "err": "ERR-001",
  24. },
  25. )
  26. return
  27. } else {
  28. context.JSON(http.StatusInternalServerError,
  29. gin.H{
  30. "description": err.Error(),
  31. "err": "unknown error",
  32. },
  33. )
  34. return
  35. }
  36. }
  37. context.FileAttachment(fileName, fileMark)
  38. context.Status(http.StatusOK)
  39. }