Major refactor, splitting user handlers into separate files and changes to how the database is accessed

This commit is contained in:
Imbus 2024-03-29 14:37:22 +01:00
parent c466a98b15
commit 13d3035e49
15 changed files with 439 additions and 400 deletions

View file

@ -0,0 +1,17 @@
package database
import "github.com/gofiber/fiber/v2"
// Simple middleware that provides a shared database pool as a local key "db"
func DbMiddleware(db *Database) func(c *fiber.Ctx) error {
return func(c *fiber.Ctx) error {
c.Locals("db", db)
return c.Next()
}
}
// Helper function to get the database from the context, without fiddling with casts
func GetDb(c *fiber.Ctx) Database {
// Dereference a pointer to a local, casted to a pointer to a Database
return *c.Locals("db").(*Database)
}