getting the flow control more like I envisioned it
This commit is contained in:
@@ -10,8 +10,8 @@ package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"git.erbosoft.com/amy/amsterdam/ui"
|
||||
"github.com/CloudyKit/jet/v6"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
@@ -24,7 +24,7 @@ var views = jet.NewSet(
|
||||
type TemplateRenderer struct {
|
||||
}
|
||||
|
||||
func (self *TemplateRenderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
|
||||
func (r *TemplateRenderer) Render(w io.Writer, name string, data any, c echo.Context) error {
|
||||
view, err := views.GetTemplate(name)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -35,9 +35,9 @@ func (self *TemplateRenderer) Render(w io.Writer, name string, data interface{},
|
||||
func setupEcho() *echo.Echo {
|
||||
e := echo.New()
|
||||
e.Renderer = &TemplateRenderer{}
|
||||
e.GET("/", func(c echo.Context) error {
|
||||
return c.Render(http.StatusOK, "frame.jet", nil)
|
||||
})
|
||||
e.GET("/", ui.AmWrap(func(ctxt ui.AmContext) (string, any, error) {
|
||||
return "template", "frame.jet", nil
|
||||
}))
|
||||
return e
|
||||
}
|
||||
|
||||
|
||||
+12
-3
@@ -9,24 +9,33 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type AmContext interface {
|
||||
Render(int, string, interface{}) error
|
||||
Render(string) error
|
||||
SetRC(int)
|
||||
}
|
||||
|
||||
type amContext struct {
|
||||
echoContext echo.Context
|
||||
httprc int
|
||||
}
|
||||
|
||||
func (c *amContext) Render(code int, name string, data interface{}) error {
|
||||
return c.echoContext.Render(code, name, data)
|
||||
func (c *amContext) Render(name string) error {
|
||||
return c.echoContext.Render(c.httprc, name, c)
|
||||
}
|
||||
|
||||
func (c *amContext) SetRC(rc int) {
|
||||
c.httprc = rc
|
||||
}
|
||||
|
||||
func NewAmContext(ctxt echo.Context) AmContext {
|
||||
rc := amContext{
|
||||
echoContext: ctxt,
|
||||
httprc: http.StatusOK,
|
||||
}
|
||||
return &rc
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Amsterdam Web Communities System
|
||||
* Copyright (c) 2025 Erbosoft Metaverse Design Solutions, All Rights Reserved
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func AmWrap(myfunc func(AmContext) (string, any, error)) echo.HandlerFunc {
|
||||
return func(ctxt echo.Context) error {
|
||||
amctxt := NewAmContext(ctxt)
|
||||
what, rc, err := myfunc(amctxt)
|
||||
if err == nil {
|
||||
switch what {
|
||||
case "template":
|
||||
err = amctxt.Render(fmt.Sprintf("%v", rc))
|
||||
default:
|
||||
err = fmt.Errorf("unknown rendering type: %s", what)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user