htmgo/main.go

38 lines
654 B
Go
Raw Normal View History

2024-01-22 15:22:16 +00:00
package main
import (
"github.com/gofiber/fiber/v2"
2024-09-11 00:52:18 +00:00
"github.com/google/uuid"
2024-01-22 15:22:16 +00:00
"mhtml/h"
2024-09-11 00:52:18 +00:00
"mhtml/pages"
"mhtml/partials"
2024-01-22 15:22:16 +00:00
)
func main() {
2024-09-11 00:52:18 +00:00
f := fiber.New()
f.Static("/js", "./js")
f.Use(func(ctx *fiber.Ctx) error {
if ctx.Cookies("mhtml-session") != "" {
return ctx.Next()
}
id := ctx.IP() + uuid.NewString()
ctx.Cookie(&fiber.Cookie{
Name: "mhtml-session",
Value: id,
SessionOnly: true,
})
return ctx.Next()
})
2024-01-22 15:22:16 +00:00
2024-09-11 00:52:18 +00:00
f.Get("/mhtml/partials.*", func(ctx *fiber.Ctx) error {
return h.PartialView(ctx, partials.GetPartialFromContext(ctx))
2024-01-22 15:22:16 +00:00
})
2024-09-11 00:52:18 +00:00
pages.RegisterPages(f)
2024-01-22 15:22:16 +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
})
}