Smarter app structure

This commit is contained in:
2025-08-08 00:24:06 +02:00
parent 20e3466f2f
commit b7cdd82d9e
7 changed files with 531 additions and 258 deletions

10
main.go
View File

@@ -6,7 +6,9 @@ import (
"fitra-backend/controllers"
"fmt"
"html/template"
"io/fs"
"log"
"net/http"
"os"
"github.com/gin-gonic/gin"
@@ -16,6 +18,9 @@ import (
//go:embed views/*
var viewsFS embed.FS
//go:embed static/*
var staticFS embed.FS
func main() {
if err := godotenv.Load(); err != nil {
log.Println("No .env file found")
@@ -24,10 +29,13 @@ func main() {
go application.StartCleanupRoutine()
r := gin.Default()
tmpl := template.Must(template.New("").ParseFS(viewsFS, "views/*.html", "views/partials/*.html"))
r.SetHTMLTemplate(tmpl)
staticSub, _ := fs.Sub(staticFS, "static")
r.StaticFS("/static", http.FS(staticSub))
r.GET("/", controllers.HandleIndex)
r.POST("/upload", controllers.HandleFileUpload)
r.GET("/uploads/:fileID/:filename", controllers.HandleFileDownload)