consolidated UI setup into a single function call from main

This commit is contained in:
2026-02-20 15:52:36 -07:00
parent 8a1c770079
commit 7ae9326292
6 changed files with 38 additions and 13 deletions
+2 -5
View File
@@ -30,6 +30,7 @@ import (
log "github.com/sirupsen/logrus"
)
// GetAndPost is used to have functions that respond to both GET and POST on a URI.
var GetAndPost = []string{http.MethodGet, http.MethodPost}
// setupEcho creates, configures, and returns a new Echo instance.
@@ -181,11 +182,7 @@ func main() {
closer = email.SetupMailSender()
defer closer()
htmlcheck.SetupDicts()
ui.SetupTemplates()
ui.SetupMenuCache()
closer = ui.SetupAmSessionManager()
defer closer()
closer = ui.SetupAmContext()
closer = ui.SetupUILayer()
defer closer()
// Set up to trap SIGINT/SIGTERM and shut down gracefully
+2 -2
View File
@@ -620,8 +620,8 @@ func contextRecycler(incoming chan *amContext, done chan bool) {
done <- true
}
// SetupAmContext starts the recycler for contexts.
func SetupAmContext() func() {
// setupContext starts the recycler for contexts.
func setupContext() func() {
amContextRecycleBin = make(chan *amContext, config.GlobalConfig.Tuning.Queues.ContextRecycle)
done := make(chan bool)
go contextRecycler(amContextRecycleBin, done)
+2 -2
View File
@@ -373,8 +373,8 @@ func (st *amSessionStore) sweep(tick <-chan time.Time, done chan bool) {
// sessionStore is the global session store.
var sessionStore *amSessionStore
// SetupAmSessionManager sets up the session store and its sweeper goroutine.
func SetupAmSessionManager() func() {
// setupSessionManager sets up the session store and its sweeper goroutine.
func setupSessionManager() func() {
// get the time for the session to expire
d, err := time.ParseDuration(config.GlobalConfig.Site.SessionExpire)
if err != nil {
+2 -2
View File
@@ -156,8 +156,8 @@ func init() {
}
}
// SetupMenuCache sets up the menu cache.
func SetupMenuCache() {
// setupMenuCache sets up the menu cache.
func setupMenuCache() {
var err error
if menuCache, err = lru.New(config.GlobalConfig.Tuning.Caches.Menus); err != nil {
panic(err)
+28
View File
@@ -0,0 +1,28 @@
/*
* Amsterdam Web Communities System
* Copyright (c) 2025-2026 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 holds the support for the Amsterdam user interface, wrapping Echo and Jet templates.
package ui
import "slices"
// SetupUILayer sets up the UI layer, and returns a function to close it down again.
func SetupUILayer() func() {
exitfuncs := make([]func(), 0, 2)
setupTemplates()
setupMenuCache()
exitfuncs = append(exitfuncs, setupSessionManager())
exitfuncs = append(exitfuncs, setupContext())
return func() {
slices.Reverse(exitfuncs)
for _, f := range exitfuncs {
f()
}
}
}
+2 -2
View File
@@ -303,8 +303,8 @@ func postRewrite(a jet.Arguments) reflect.Value {
return reflect.ValueOf(data)
}
// SetupTemplates is called to set up the template renderer after the configuration is loaded.
func SetupTemplates() {
// setupTemplates is called to set up the template renderer after the configuration is loaded.
func setupTemplates() {
views = jet.NewSet(
multi.NewLoader(
jet.NewOSFileSystemLoader(config.GlobalConfig.Rendering.TemplateDir),