refactor: new (simpler) version of the sl library
This commit is contained in:
+16
-12
@@ -9,35 +9,39 @@ import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
var Slot = sl.NewSlot[*Dev]()
|
||||
|
||||
type Dev struct {
|
||||
HtmlRouteBindings map[string]string
|
||||
}
|
||||
|
||||
func (m *Dev) Initialize(l *sl.ServiceLocator) error {
|
||||
m.HtmlRouteBindings = map[string]string{}
|
||||
|
||||
router, err := sl.Use[*routes.Router](l)
|
||||
if err != nil {
|
||||
return err
|
||||
func New(l *sl.ServiceLocator) (*Dev, error) {
|
||||
dev := &Dev{
|
||||
map[string]string{},
|
||||
}
|
||||
|
||||
router.Get("/api/dev/routes", func(c *fiber.Ctx) error {
|
||||
return c.JSON(m.HtmlRouteBindings)
|
||||
router, err := sl.Use(l, routes.Api)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
router.Get("/dev/routes", func(c *fiber.Ctx) error {
|
||||
return c.JSON(dev.HtmlRouteBindings)
|
||||
})
|
||||
|
||||
return nil
|
||||
return dev, nil
|
||||
}
|
||||
|
||||
// UseVitePage this hook will link the provided "mountPoint" to the "frontendHtml" page
|
||||
func UseVitePage[T any](l *sl.ServiceLocator, mountPoint, frontendHtml string) func(c *fiber.Ctx) error {
|
||||
func UseVitePage(l *sl.ServiceLocator, mountPoint, frontendHtml string) func(c *fiber.Ctx) error {
|
||||
log.Printf(`registering vite route %q for %q`, frontendHtml, mountPoint)
|
||||
|
||||
dev, err := sl.Use[*Dev](l)
|
||||
dev, err := sl.Use(l, Slot)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
dev.HtmlRouteBindings[mountPoint] = path.Join("./frontend/", frontendHtml)
|
||||
dev.HtmlRouteBindings[mountPoint] = frontendHtml
|
||||
|
||||
return func(c *fiber.Ctx) error {
|
||||
return c.SendFile(path.Join("./out/frontend/", frontendHtml))
|
||||
|
||||
Reference in New Issue
Block a user