consolidated UI setup into a single function call from main
This commit is contained in:
@@ -30,6 +30,7 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
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}
|
var GetAndPost = []string{http.MethodGet, http.MethodPost}
|
||||||
|
|
||||||
// setupEcho creates, configures, and returns a new Echo instance.
|
// setupEcho creates, configures, and returns a new Echo instance.
|
||||||
@@ -181,11 +182,7 @@ func main() {
|
|||||||
closer = email.SetupMailSender()
|
closer = email.SetupMailSender()
|
||||||
defer closer()
|
defer closer()
|
||||||
htmlcheck.SetupDicts()
|
htmlcheck.SetupDicts()
|
||||||
ui.SetupTemplates()
|
closer = ui.SetupUILayer()
|
||||||
ui.SetupMenuCache()
|
|
||||||
closer = ui.SetupAmSessionManager()
|
|
||||||
defer closer()
|
|
||||||
closer = ui.SetupAmContext()
|
|
||||||
defer closer()
|
defer closer()
|
||||||
|
|
||||||
// Set up to trap SIGINT/SIGTERM and shut down gracefully
|
// Set up to trap SIGINT/SIGTERM and shut down gracefully
|
||||||
|
|||||||
+2
-2
@@ -620,8 +620,8 @@ func contextRecycler(incoming chan *amContext, done chan bool) {
|
|||||||
done <- true
|
done <- true
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupAmContext starts the recycler for contexts.
|
// setupContext starts the recycler for contexts.
|
||||||
func SetupAmContext() func() {
|
func setupContext() func() {
|
||||||
amContextRecycleBin = make(chan *amContext, config.GlobalConfig.Tuning.Queues.ContextRecycle)
|
amContextRecycleBin = make(chan *amContext, config.GlobalConfig.Tuning.Queues.ContextRecycle)
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
go contextRecycler(amContextRecycleBin, done)
|
go contextRecycler(amContextRecycleBin, done)
|
||||||
|
|||||||
+2
-2
@@ -373,8 +373,8 @@ func (st *amSessionStore) sweep(tick <-chan time.Time, done chan bool) {
|
|||||||
// sessionStore is the global session store.
|
// sessionStore is the global session store.
|
||||||
var sessionStore *amSessionStore
|
var sessionStore *amSessionStore
|
||||||
|
|
||||||
// SetupAmSessionManager sets up the session store and its sweeper goroutine.
|
// setupSessionManager sets up the session store and its sweeper goroutine.
|
||||||
func SetupAmSessionManager() func() {
|
func setupSessionManager() func() {
|
||||||
// get the time for the session to expire
|
// get the time for the session to expire
|
||||||
d, err := time.ParseDuration(config.GlobalConfig.Site.SessionExpire)
|
d, err := time.ParseDuration(config.GlobalConfig.Site.SessionExpire)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+2
-2
@@ -156,8 +156,8 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupMenuCache sets up the menu cache.
|
// setupMenuCache sets up the menu cache.
|
||||||
func SetupMenuCache() {
|
func setupMenuCache() {
|
||||||
var err error
|
var err error
|
||||||
if menuCache, err = lru.New(config.GlobalConfig.Tuning.Caches.Menus); err != nil {
|
if menuCache, err = lru.New(config.GlobalConfig.Tuning.Caches.Menus); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
+28
@@ -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
@@ -303,8 +303,8 @@ func postRewrite(a jet.Arguments) reflect.Value {
|
|||||||
return reflect.ValueOf(data)
|
return reflect.ValueOf(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupTemplates is called to set up the template renderer after the configuration is loaded.
|
// setupTemplates is called to set up the template renderer after the configuration is loaded.
|
||||||
func SetupTemplates() {
|
func setupTemplates() {
|
||||||
views = jet.NewSet(
|
views = jet.NewSet(
|
||||||
multi.NewLoader(
|
multi.NewLoader(
|
||||||
jet.NewOSFileSystemLoader(config.GlobalConfig.Rendering.TemplateDir),
|
jet.NewOSFileSystemLoader(config.GlobalConfig.Rendering.TemplateDir),
|
||||||
|
|||||||
Reference in New Issue
Block a user