Smarter app structure
This commit is contained in:
10
main.go
10
main.go
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user