diff --git a/server.go b/server.go index 0f19756..51b6124 100644 --- a/server.go +++ b/server.go @@ -9,6 +9,8 @@ package main import ( + "fmt" + "git.erbosoft.com/amy/amsterdam/ui" "github.com/labstack/echo/v4" ) @@ -16,6 +18,9 @@ import ( func setupEcho() *echo.Echo { e := echo.New() e.Renderer = &ui.TemplateRenderer{} + e.GET("/img/*", ui.AmWrap(func(ctxt ui.AmContext) (string, any, error) { + return "string", fmt.Sprintf("Path: %s", ctxt.URLPath()), nil + })) e.GET("/", ui.AmWrap(func(ctxt ui.AmContext) (string, any, error) { ctxt.VarMap().Set("amsterdam_pageTitle", "My Front Page") return "framed_template", "top.jet", nil diff --git a/ui/amcontext.go b/ui/amcontext.go index 174800a..5aa3320 100644 --- a/ui/amcontext.go +++ b/ui/amcontext.go @@ -17,9 +17,11 @@ import ( ) type AmContext interface { + RC() int Render(string) error SubRender(string) ([]byte, error) SetRC(int) + URLPath() string VarMap() jet.VarMap } @@ -29,6 +31,10 @@ type amContext struct { rendervars jet.VarMap } +func (c *amContext) RC() int { + return c.httprc +} + func (c *amContext) Render(name string) error { return c.echoContext.Render(c.httprc, name, c) } @@ -47,6 +53,10 @@ func (c *amContext) SetRC(rc int) { c.httprc = rc } +func (c *amContext) URLPath() string { + return c.echoContext.Request().URL.Path +} + func (c *amContext) VarMap() jet.VarMap { return c.rendervars } diff --git a/ui/render_wrap.go b/ui/render_wrap.go index 5286848..38e44c3 100644 --- a/ui/render_wrap.go +++ b/ui/render_wrap.go @@ -20,6 +20,8 @@ func AmWrap(myfunc func(AmContext) (string, any, error)) echo.HandlerFunc { what, rc, err := myfunc(amctxt) if err == nil { switch what { + case "string": + err = ctxt.String(amctxt.RC(), fmt.Sprintf("%v", rc)) case "template": err = amctxt.Render(fmt.Sprintf("%v", rc)) case "framed_template":