-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (38 loc) · 930 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"log"
"todo-app/models"
"todo-app/routes"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/template/html/v2"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
var db *gorm.DB
func main() {
// Initialize the HTML template engine
htmlEngine := html.New("./views", ".html")
// Initialize Fiber app
app := fiber.New(fiber.Config{
Views: htmlEngine,
})
app.Use(logger.New())
// Initialize SQLite database
var err error
db, err = gorm.Open(sqlite.Open("tasks.db"), &gorm.Config{})
if err != nil {
panic("failed to connect to database")
}
// Migrate the Task model
if err := models.MigrateTask(db); err != nil {
panic("failed to migrate database")
}
routes.SetupTaskRoutes(app, db)
// Define the port
port := ":3000"
// Start the server
if err := app.Listen(port); err != nil {
log.Fatalf("Failed to start server: %v", err)
}
}