From 779f15f069127652609f21032174ab92d80dc547 Mon Sep 17 00:00:00 2001 From: Amy Gale Ruth Bowersox Date: Sat, 13 Sep 2025 22:46:02 -0600 Subject: [PATCH] working in configuration data and replacing values in frame template --- .vscode/launch.json | 8 ++++++++ config/config.go | 32 ++++++++++++++++++++++++++++++++ config/default.yaml | 2 ++ go.mod | 1 + go.sum | 3 +++ server.go | 1 + ui/render_wrap.go | 5 +++++ ui/templates.go | 5 +++++ views/frame.jet | 2 +- 9 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 .vscode/launch.json create mode 100644 config/config.go create mode 100644 config/default.yaml diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..b8d2d84 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,8 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + ] +} \ No newline at end of file diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..17c6d34 --- /dev/null +++ b/config/config.go @@ -0,0 +1,32 @@ +/* + * 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 config + +import ( + _ "embed" + + "gopkg.in/yaml.v3" +) + +type AmConfig struct { + Site struct { + Title string `yaml:"title"` + } `yaml:"site"` +} + +//go:embed default.yaml +var defaultConfigData []byte + +var GlobalConfig AmConfig + +func init() { + var defaultConfig AmConfig + yaml.Unmarshal(defaultConfigData, &defaultConfig) + GlobalConfig = defaultConfig +} diff --git a/config/default.yaml b/config/default.yaml new file mode 100644 index 0000000..291f8b7 --- /dev/null +++ b/config/default.yaml @@ -0,0 +1,2 @@ +site: + title: "Amsterdam Web Communities System" diff --git a/go.mod b/go.mod index 8d5519e..b0fa476 100644 --- a/go.mod +++ b/go.mod @@ -15,4 +15,5 @@ require ( golang.org/x/net v0.40.0 // indirect golang.org/x/sys v0.33.0 // indirect golang.org/x/text v0.25.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index de9e125..6eb77ad 100644 --- a/go.sum +++ b/go.sum @@ -23,3 +23,6 @@ golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4= golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/server.go b/server.go index 616a8eb..0f19756 100644 --- a/server.go +++ b/server.go @@ -17,6 +17,7 @@ func setupEcho() *echo.Echo { e := echo.New() e.Renderer = &ui.TemplateRenderer{} 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 })) return e diff --git a/ui/render_wrap.go b/ui/render_wrap.go index fe8089e..5286848 100644 --- a/ui/render_wrap.go +++ b/ui/render_wrap.go @@ -28,6 +28,11 @@ func AmWrap(myfunc func(AmContext) (string, any, error)) echo.HandlerFunc { default: err = fmt.Errorf("unknown rendering type: %s", what) } + if err != nil { + ctxt.Logger().Error("Rendering error: %v", err) + } + } else { + ctxt.Logger().Error("Page function error: %v", err) } return err } diff --git a/ui/templates.go b/ui/templates.go index db9d4e4..c537831 100644 --- a/ui/templates.go +++ b/ui/templates.go @@ -11,6 +11,7 @@ package ui import ( "io" + "git.erbosoft.com/amy/amsterdam/config" "github.com/CloudyKit/jet/v6" "github.com/labstack/echo/v4" ) @@ -20,6 +21,10 @@ var views = jet.NewSet( jet.DevelopmentMode(true), ) +func init() { + views.AddGlobal("GlobalConfig", config.GlobalConfig) +} + type TemplateRenderer struct { } diff --git a/views/frame.jet b/views/frame.jet index 85fd763..217f0d6 100644 --- a/views/frame.jet +++ b/views/frame.jet @@ -3,7 +3,7 @@ - My Front Page - Venice Test + {{ amsterdam_pageTitle }} - {{ GlobalConfig.Site.Title }}