getting the flow control more like I envisioned it
This commit is contained in:
@@ -10,8 +10,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
|
||||||
|
|
||||||
|
"git.erbosoft.com/amy/amsterdam/ui"
|
||||||
"github.com/CloudyKit/jet/v6"
|
"github.com/CloudyKit/jet/v6"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
@@ -24,7 +24,7 @@ var views = jet.NewSet(
|
|||||||
type TemplateRenderer struct {
|
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)
|
view, err := views.GetTemplate(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -35,9 +35,9 @@ func (self *TemplateRenderer) Render(w io.Writer, name string, data interface{},
|
|||||||
func setupEcho() *echo.Echo {
|
func setupEcho() *echo.Echo {
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
e.Renderer = &TemplateRenderer{}
|
e.Renderer = &TemplateRenderer{}
|
||||||
e.GET("/", func(c echo.Context) error {
|
e.GET("/", ui.AmWrap(func(ctxt ui.AmContext) (string, any, error) {
|
||||||
return c.Render(http.StatusOK, "frame.jet", nil)
|
return "template", "frame.jet", nil
|
||||||
})
|
}))
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-3
@@ -9,24 +9,33 @@
|
|||||||
package ui
|
package ui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AmContext interface {
|
type AmContext interface {
|
||||||
Render(int, string, interface{}) error
|
Render(string) error
|
||||||
|
SetRC(int)
|
||||||
}
|
}
|
||||||
|
|
||||||
type amContext struct {
|
type amContext struct {
|
||||||
echoContext echo.Context
|
echoContext echo.Context
|
||||||
|
httprc int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *amContext) Render(code int, name string, data interface{}) error {
|
func (c *amContext) Render(name string) error {
|
||||||
return c.echoContext.Render(code, name, data)
|
return c.echoContext.Render(c.httprc, name, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *amContext) SetRC(rc int) {
|
||||||
|
c.httprc = rc
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAmContext(ctxt echo.Context) AmContext {
|
func NewAmContext(ctxt echo.Context) AmContext {
|
||||||
rc := amContext{
|
rc := amContext{
|
||||||
echoContext: ctxt,
|
echoContext: ctxt,
|
||||||
|
httprc: http.StatusOK,
|
||||||
}
|
}
|
||||||
return &rc
|
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