Major refactor, splitting user handlers into separate files and changes to how the database is accessed
This commit is contained in:
parent
c466a98b15
commit
13d3035e49
15 changed files with 439 additions and 400 deletions
17
backend/internal/database/middleware.go
Normal file
17
backend/internal/database/middleware.go
Normal 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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue