babillard/handlers/contenu.go
Victor Lacasse-Beaudoin 17de134f76 Déplacer functions de serverCmd vers data/ et handlers/
Déplacer ListContenu vers data/

Déplacer handlers / et /api vers handlers/handlers.go

Déplacer handlers /api/contenu vers handlers/contenu.go
2023-05-05 18:59:53 -04:00

39 lines
867 B
Go

package handlers
import (
"fmt"
"log"
"net/http"
"strings"
"git.agecem.com/agecem/babillard/data"
"github.com/labstack/echo/v4"
"github.com/spf13/viper"
)
func HandleAPIContenuList(c echo.Context) error {
contenu_dir := viper.GetString("server.contenu_dir")
files, err := data.ListContenu(contenu_dir)
if err != nil {
log.Println(err)
return c.JSON(http.StatusInternalServerError, map[string]string{
"message": "Internal Server Error",
"error": err.Error(),
})
}
return c.String(http.StatusOK, strings.Join(files, ";"))
}
func HandleAPIContenuFile(c echo.Context) error {
filename := c.Param("filename")
contenu_dir := viper.GetString("server.contenu_dir")
if filename == ".gitkeep" {
return c.JSON(http.StatusNotFound, map[string]string{"message": "Not Found"})
}
return c.File(fmt.Sprintf("%s/%s", contenu_dir, filename))
}