Add clan-purge and player-purge. Optimized performance with template-init.

This commit is contained in:
MaxJa4
2024-01-20 17:14:47 +01:00
parent e5d13f2270
commit 9e3e2723d3
6 changed files with 94 additions and 59 deletions

48
main.go
View File

@@ -6,11 +6,55 @@ import (
"InfantrySkillCalculator/utils"
"github.com/gin-gonic/gin"
_ "github.com/gorilla/sessions"
"html/template"
"io"
"log"
"os"
)
var mainPageTemplates *template.Template
var loginPageTemplates *template.Template
var registerPageTemplates *template.Template
func init() {
var err error
mainPageTemplates, err = template.ParseFiles(
"./templates/index.html",
"./templates/components/home_clan_bar.html",
"./templates/components/opp_clan_bar.html",
"./templates/components/home_player_list.html",
"./templates/components/opp_player_list.html",
"./templates/components/bottom_controls.html",
"./templates/modals/delete_clan.html",
"./templates/modals/add_clan.html",
"./templates/modals/edit_clan.html",
"./templates/modals/add_player.html",
"./templates/modals/delete_player.html",
"./templates/modals/edit_player.html",
"./templates/modals/settings.html",
"./templates/components/header.html",
)
if err != nil {
log.Fatal(err)
}
loginPageTemplates, err = template.ParseFiles(
"./templates/login.html",
"./templates/components/header.html",
)
if err != nil {
log.Fatal(err)
}
registerPageTemplates, err = template.ParseFiles(
"./templates/register.html",
"./templates/components/header.html",
)
if err != nil {
log.Fatal(err)
}
}
func main() {
//gin.SetMode(gin.ReleaseMode) // uncomment upon release
@@ -73,7 +117,9 @@ func main() {
protected.GET("/settings", controllers.GetSettings)
protected.PATCH("/settings", controllers.UpdateSettings)
admin.GET("/clear_cache", controllers.DeleteAllCaches)
admin.DELETE("/clear_cache", controllers.DeleteAllCaches)
admin.DELETE("/purge_players", controllers.DeleteAllPlayers)
admin.DELETE("/purge_clans", controllers.DeleteAllClans)
admin.POST("/create_code", controllers.CreateCode)
log.Println("Running on 8000...")