| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package controller
- import (
- "kng_feed_api/helper"
- "net/http"
- "os"
- "path/filepath"
- "github.com/gin-gonic/gin"
- )
- func SendXmlFeedToClient(context *gin.Context) {
- sendFile(context, "feed.xml")
- }
- func SendCsvDeltaToClient(context *gin.Context) {
- sendFile(context, "delta.csv")
- }
- func sendFile(context *gin.Context, fileMark string) {
- var fileName = filepath.Join(helper.RootDir(), fileMark)
- _, 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, fileMark)
- context.Status(http.StatusOK)
- }
|