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)
| 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. |
| 59 | func 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 | |
| 93 | func adminItemsRankWeapons(w http.ResponseWriter, r *http.Request) { |
| 94 | serveAdminTemplate(w, r, "items-rank-weapons.html", nil) |
no test coverage detected