diff --git a/main.go b/main.go index 1deb790..8cdb6ac 100644 --- a/main.go +++ b/main.go @@ -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 diff --git a/ui/amcontext.go b/ui/amcontext.go index a145d25..cbbfe56 100644 --- a/ui/amcontext.go +++ b/ui/amcontext.go @@ -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) diff --git a/ui/amsession.go b/ui/amsession.go index 0a304a8..03fc448 100644 --- a/ui/amsession.go +++ b/ui/amsession.go @@ -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 { diff --git a/ui/menus.go b/ui/menus.go index 54697b7..884fbe9 100644 --- a/ui/menus.go +++ b/ui/menus.go @@ -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) diff --git a/ui/setup.go b/ui/setup.go new file mode 100644 index 0000000..42e9b0c --- /dev/null +++ b/ui/setup.go @@ -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() + } + } +} diff --git a/ui/templates.go b/ui/templates.go index cfbc784..d618ad7 100644 --- a/ui/templates.go +++ b/ui/templates.go @@ -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),