figure out where to serve static images from and how to handle "wildcard" paths
This commit is contained in:
@@ -9,6 +9,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"git.erbosoft.com/amy/amsterdam/ui"
|
"git.erbosoft.com/amy/amsterdam/ui"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
@@ -16,6 +18,9 @@ import (
|
|||||||
func setupEcho() *echo.Echo {
|
func setupEcho() *echo.Echo {
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
e.Renderer = &ui.TemplateRenderer{}
|
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) {
|
e.GET("/", ui.AmWrap(func(ctxt ui.AmContext) (string, any, error) {
|
||||||
ctxt.VarMap().Set("amsterdam_pageTitle", "My Front Page")
|
ctxt.VarMap().Set("amsterdam_pageTitle", "My Front Page")
|
||||||
return "framed_template", "top.jet", nil
|
return "framed_template", "top.jet", nil
|
||||||
|
|||||||
@@ -17,9 +17,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type AmContext interface {
|
type AmContext interface {
|
||||||
|
RC() int
|
||||||
Render(string) error
|
Render(string) error
|
||||||
SubRender(string) ([]byte, error)
|
SubRender(string) ([]byte, error)
|
||||||
SetRC(int)
|
SetRC(int)
|
||||||
|
URLPath() string
|
||||||
VarMap() jet.VarMap
|
VarMap() jet.VarMap
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,6 +31,10 @@ type amContext struct {
|
|||||||
rendervars jet.VarMap
|
rendervars jet.VarMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *amContext) RC() int {
|
||||||
|
return c.httprc
|
||||||
|
}
|
||||||
|
|
||||||
func (c *amContext) Render(name string) error {
|
func (c *amContext) Render(name string) error {
|
||||||
return c.echoContext.Render(c.httprc, name, c)
|
return c.echoContext.Render(c.httprc, name, c)
|
||||||
}
|
}
|
||||||
@@ -47,6 +53,10 @@ func (c *amContext) SetRC(rc int) {
|
|||||||
c.httprc = rc
|
c.httprc = rc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *amContext) URLPath() string {
|
||||||
|
return c.echoContext.Request().URL.Path
|
||||||
|
}
|
||||||
|
|
||||||
func (c *amContext) VarMap() jet.VarMap {
|
func (c *amContext) VarMap() jet.VarMap {
|
||||||
return c.rendervars
|
return c.rendervars
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ func AmWrap(myfunc func(AmContext) (string, any, error)) echo.HandlerFunc {
|
|||||||
what, rc, err := myfunc(amctxt)
|
what, rc, err := myfunc(amctxt)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
switch what {
|
switch what {
|
||||||
|
case "string":
|
||||||
|
err = ctxt.String(amctxt.RC(), fmt.Sprintf("%v", rc))
|
||||||
case "template":
|
case "template":
|
||||||
err = amctxt.Render(fmt.Sprintf("%v", rc))
|
err = amctxt.Render(fmt.Sprintf("%v", rc))
|
||||||
case "framed_template":
|
case "framed_template":
|
||||||
|
|||||||
Reference in New Issue
Block a user