htmgo/starter-template/main.go

37 lines
728 B
Go
Raw Normal View History

2024-01-22 15:22:16 +00:00
package main
import (
"github.com/gofiber/fiber/v2"
2024-09-14 00:05:55 +00:00
"github.com/maddalax/htmgo/framework/h"
2024-09-11 17:31:40 +00:00
"log"
2024-09-13 21:33:50 +00:00
"starter-template/pages"
"starter-template/partials/load"
2024-09-11 17:31:40 +00:00
"time"
2024-01-22 15:22:16 +00:00
)
func main() {
2024-09-11 00:52:18 +00:00
f := fiber.New()
f.Static("/public", "./assets/dist")
2024-09-11 00:52:18 +00:00
2024-09-11 17:31:40 +00:00
f.Use(func(ctx *fiber.Ctx) error {
if ctx.Path() == "/livereload" {
return ctx.Next()
}
now := time.Now()
err := ctx.Next()
duration := time.Since(now)
ctx.Set("X-Response-Time", duration.String())
// Log or print the request method, URL, and duration
2024-09-12 02:06:34 +00:00
log.Printf("Request: %s %s took %dms", ctx.Method(), ctx.OriginalURL(), duration.Milliseconds())
2024-09-11 17:31:40 +00:00
return err
})
load.RegisterPartials(f)
2024-09-11 00:52:18 +00:00
pages.RegisterPages(f)
2024-09-12 02:06:34 +00:00
2024-09-11 00:52:18 +00:00
h.Start(f, h.App{
LiveReload: true,
2024-01-22 15:22:16 +00:00
})
}