MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / serveAdminTemplate

Function serveAdminTemplate

internal/web/admin_items.go:59–91  ·  view source on GitHub ↗

serveAdminTemplate is a helper that parses and executes a named admin HTML template, merging any extra data into the standard template data map.

(w http.ResponseWriter, r *http.Request, filename string, extra map[string]any)

Source from the content-addressed store, hash-verified

57// serveAdminTemplate is a helper that parses and executes a named admin HTML
58// template, merging any extra data into the standard template data map.
59func serveAdminTemplate(w http.ResponseWriter, r *http.Request, filename string, extra map[string]any) {
60 adminHtml := configs.GetFilePathsConfig().AdminHtml.String()
61
62 tmpl, err := template.New(filename).Funcs(funcMap).ParseFiles(
63 adminHtml+"/_header.html",
64 adminHtml+"/_nav.html",
65 adminHtml+"/"+filename,
66 adminHtml+"/_footer.html",
67 )
68 if err != nil {
69 mudlog.Error("HTML ERROR", "error", err)
70 http.Error(w, "Error parsing template files", http.StatusInternalServerError)
71 return
72 }
73
74 writeKey := pageWritePermissions[strings.TrimRight(r.URL.Path, "/")]
75 templateData := map[string]any{
76 "CONFIG": configs.GetConfig(),
77 "STATS": GetStats(),
78 "NAV": buildAdminNav(),
79 "AUTHED_USER": GetAuthedUser(r),
80 "WRITE_PERMISSION": writeKey,
81 "READ_ONLY": pageReadOnly(r),
82 }
83 for k, v := range extra {
84 templateData[k] = v
85 }
86
87 w.Header().Set("Cache-Control", "no-store")
88 if err := tmpl.Execute(w, templateData); err != nil {
89 mudlog.Error("HTML ERROR", "action", "Execute", "error", err)
90 }
91}
92
93func adminItemsRankWeapons(w http.ResponseWriter, r *http.Request) {
94 serveAdminTemplate(w, r, "items-rank-weapons.html", nil)

Callers 15

adminPanelsFunction · 0.85
adminPanelsAPIFunction · 0.85
adminItemsRankWeaponsFunction · 0.85
adminItemsFunction · 0.85
adminItemsAPIFunction · 0.85
adminItemsAttackMessagesFunction · 0.85
adminItemsRankArmorFunction · 0.85
adminBuffsFunction · 0.85
adminBuffsAPIFunction · 0.85
adminQuestsFunction · 0.85
adminQuestsAPIFunction · 0.85

Calls 10

GetFilePathsConfigFunction · 0.92
ErrorFunction · 0.92
GetConfigFunction · 0.92
GetStatsFunction · 0.85
buildAdminNavFunction · 0.85
GetAuthedUserFunction · 0.85
pageReadOnlyFunction · 0.85
NewMethod · 0.80
StringMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected