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

Function adminIndex

internal/web/admin.go:12–51  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

10)
11
12func adminIndex(w http.ResponseWriter, r *http.Request) {
13
14 adminHtml := configs.GetFilePathsConfig().AdminHtml.String()
15
16 tmpl, err := template.New("index.html").Funcs(funcMap).ParseFiles(
17 adminHtml+"/_header.html",
18 adminHtml+"/_nav.html",
19 adminHtml+"/index.html",
20 adminHtml+"/_footer.html",
21 )
22 if err != nil {
23 mudlog.Error("HTML ERROR", "error", err)
24 http.Error(w, "Error parsing template files", http.StatusInternalServerError)
25 return
26 }
27
28 writeKey := pageWritePermissions[strings.TrimRight(r.URL.Path, "/")]
29 templateData := map[string]any{
30 "CONFIG": configs.GetConfig(),
31 "STATS": GetStats(),
32 "NAV": buildAdminNav(),
33 "AUTHED_USER": GetAuthedUser(r),
34 "WRITE_PERMISSION": writeKey,
35 "READ_ONLY": pageReadOnly(r),
36 }
37
38 if r.URL.Query().Get(`login`) != `` {
39 scheme := "http"
40 if r.TLS != nil {
41 scheme = "https"
42 }
43 http.Redirect(w, r, scheme+"://"+r.Host+"/admin/", http.StatusTemporaryRedirect)
44 return
45 }
46
47 w.Header().Set("Cache-Control", "no-store")
48 if err := tmpl.Execute(w, templateData); err != nil {
49 mudlog.Error("HTML ERROR", "action", "Execute", "error", err)
50 }
51}

Callers

nothing calls this directly

Calls 11

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
GetMethod · 0.45

Tested by

no test coverage detected