| 123456789101112131415161718192021222324252627282930313233343536 |
- package controller
- import (
- "kng_feed_api/helper"
- "net/http"
- "os"
- "path/filepath"
- "github.com/gin-gonic/gin"
- )
- func SendFileToClient(context *gin.Context) {
- var fileName = filepath.Join(helper.RootDir(), "feed.xml")
- _, err := os.Stat(fileName)
- if err != nil {
- if os.IsNotExist(err) {
- context.JSON(http.StatusInternalServerError,
- gin.H{
- "description": "The file does not exist yet. Contact the administrator.",
- "err": "ERR-001",
- },
- )
- return
- } else {
- context.JSON(http.StatusInternalServerError,
- gin.H{
- "description": err.Error(),
- "err": "unknown error",
- },
- )
- return
- }
- }
- context.FileAttachment(fileName, "feed.xml")
- context.Status(http.StatusOK)
- }
|