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
|
||||
|
||||
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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user