Remove fiber ctx from render
This commit is contained in:
@ -1,16 +1,19 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fiber-sessions/app/router/requests"
|
||||||
|
|
||||||
"github.com/a-h/templ"
|
"github.com/a-h/templ"
|
||||||
"github.com/gofiber/fiber/v2"
|
|
||||||
"github.com/gofiber/fiber/v2/middleware/adaptor"
|
"github.com/gofiber/fiber/v2/middleware/adaptor"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type RequestHandler = func(request *requests.Request) error
|
||||||
|
|
||||||
// example taken from https://github.com/a-h/templ/tree/main/examples/integration-gofiber
|
// example taken from https://github.com/a-h/templ/tree/main/examples/integration-gofiber
|
||||||
func Render(c *fiber.Ctx, component templ.Component, options ...func(*templ.ComponentHandler)) error {
|
func Render(request *requests.Request, component templ.Component, options ...func(*templ.ComponentHandler)) error {
|
||||||
componentHandler := templ.Handler(component)
|
componentHandler := templ.Handler(component)
|
||||||
for _, o := range options {
|
for _, o := range options {
|
||||||
o(componentHandler)
|
o(componentHandler)
|
||||||
}
|
}
|
||||||
return adaptor.HTTPHandler(componentHandler)(c)
|
return adaptor.HTTPHandler(componentHandler)(request.Ctx)
|
||||||
}
|
}
|
||||||
@ -10,6 +10,6 @@ func Home(request *requests.Request) error {
|
|||||||
Title: "Welcome to the demo",
|
Title: "Welcome to the demo",
|
||||||
ActivePage: "home",
|
ActivePage: "home",
|
||||||
}
|
}
|
||||||
Render(request.Ctx, templates.Home(request, pc))
|
Render(request, templates.Home(request, pc))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ var pcLogin templates.PageContext = templates.PageContext{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Login(request *requests.Request) error {
|
func Login(request *requests.Request) error {
|
||||||
Render(request.Ctx, templates.RenderLogin(request, pcLogin))
|
Render(request, templates.RenderLogin(request, pcLogin))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,6 +42,6 @@ func LoginSubmit(request *requests.Request) error {
|
|||||||
content.LoginError = "Invalid username or password"
|
content.LoginError = "Invalid username or password"
|
||||||
}
|
}
|
||||||
|
|
||||||
Render(request.Ctx, templates.LoginFormContent(content))
|
Render(request, templates.LoginFormContent(content))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,6 @@ func ProtectedPage(request *requests.Request) error {
|
|||||||
Title: "Protected page",
|
Title: "Protected page",
|
||||||
ActivePage: "protected-page",
|
ActivePage: "protected-page",
|
||||||
}
|
}
|
||||||
Render(request.Ctx, templates.ProtectedPage(request, pc))
|
Render(request, templates.ProtectedPage(request, pc))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +0,0 @@
|
|||||||
package handlers
|
|
||||||
|
|
||||||
import "fiber-sessions/app/router/requests"
|
|
||||||
|
|
||||||
type RequestHandler = func(request *requests.Request) error
|
|
||||||
Reference in New Issue
Block a user