Add logger & implement fiber error handling

This commit is contained in:
William Bouzourène 2025-01-20 17:24:19 +01:00
parent 37c0480e0e
commit 6b13bb3fbf
Signed by: bouzoure
SSH key fingerprint: SHA256:19MbXpLua4rUtk8tunMesD8KUKb91LXLHg8E/qTooww
8 changed files with 400 additions and 25 deletions

21
main.go
View file

@ -4,7 +4,6 @@ import (
"embed"
"fmt"
"io/fs"
"log"
"net/http"
"git.readonly.ch/bouzoure/pop-camarades/controllers"
@ -25,28 +24,21 @@ var embedStatic embed.FS
var embedViews embed.FS
func main() {
log := helpers.GetLogger()
config, err := helpers.GetConfig()
if err != nil {
// TODO: Handle exception
log.Fatal(err)
}
_, err = helpers.GetDatabase()
if err != nil {
// TODO: Handle exception
log.Fatal(err)
}
accountCheck, err := helpers.FirstAccountCheck()
if err != nil {
// TODO: Handle exception
log.Fatal(err)
}
if !accountCheck {
err = helpers.FirstAccountCreate()
if err != nil {
// TODO: Handle exception
log.Fatal(err)
}
}
@ -71,7 +63,8 @@ func main() {
pongo2.RegisterFilter("time_diff", helpers.TemplTimeDiff)
app := fiber.New(fiber.Config{
Views: engine,
Views: engine,
ErrorHandler: helpers.FiberErrorHandler,
})
if config.Debug {
@ -205,6 +198,12 @@ func main() {
app.Post("/admin/roles/:id<int;min(0)>/edit", controllers.RoleEdit)
app.Post("/admin/roles/:id<int;min(0)>/delete", controllers.RoleDelete)
log.Info(
"starting web server",
"address", config.App.ListenAddress,
"port", config.App.ListenPort,
)
listenAddr := fmt.Sprintf(
"%s:%d",
config.App.ListenAddress,