|
|
@ -3,7 +3,6 @@ package main |
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"encoding/json" |
|
|
|
"encoding/json" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"io/ioutil" |
|
|
|
|
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"path/filepath" |
|
|
|
"path/filepath" |
|
|
@ -20,7 +19,7 @@ var ( |
|
|
|
|
|
|
|
|
|
|
|
func topWrapper(r *http.Request) string { |
|
|
|
func topWrapper(r *http.Request) string { |
|
|
|
defer log.PanicSafe() |
|
|
|
defer log.PanicSafe() |
|
|
|
headerTemplate, err := ioutil.ReadFile("./static/header.tpl") |
|
|
|
headerTemplate, err := os.ReadFile("./static/header.tpl") |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.LogError(fmt.Sprintf("Unable to open header template: ```%+v```", err)) |
|
|
|
log.LogError(fmt.Sprintf("Unable to open header template: ```%+v```", err)) |
|
|
|
return "" |
|
|
|
return "" |
|
|
@ -37,7 +36,7 @@ func topWrapper(r *http.Request) string { |
|
|
|
|
|
|
|
|
|
|
|
func bodyWrapper(r *http.Request, template string) string { |
|
|
|
func bodyWrapper(r *http.Request, template string) string { |
|
|
|
defer log.PanicSafe() |
|
|
|
defer log.PanicSafe() |
|
|
|
bodyTemplate, err := ioutil.ReadFile(fmt.Sprintf("./static/%+v.tpl", template)) |
|
|
|
bodyTemplate, err := os.ReadFile(fmt.Sprintf("./static/%+v.tpl", template)) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.LogError(fmt.Sprintf("Attempt to load %s.tpl failed. ```%+v```", template, err)) |
|
|
|
log.LogError(fmt.Sprintf("Attempt to load %s.tpl failed. ```%+v```", template, err)) |
|
|
|
return bodyWrapper(r, "404") |
|
|
|
return bodyWrapper(r, "404") |
|
|
@ -58,7 +57,7 @@ func greetUser(w http.ResponseWriter, r *http.Request) { |
|
|
|
loggedIn, _ := detectUser(r, "Homepage") |
|
|
|
loggedIn, _ := detectUser(r, "Homepage") |
|
|
|
|
|
|
|
|
|
|
|
if loggedIn { |
|
|
|
if loggedIn { |
|
|
|
bodyTemplate, _ := ioutil.ReadFile("./static/index.html") |
|
|
|
bodyTemplate, _ := os.ReadFile("./static/index.html") |
|
|
|
fmt.Fprint(w, string(bodyTemplate)) |
|
|
|
fmt.Fprint(w, string(bodyTemplate)) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
fmt.Fprint(w, pageBuilder(r, "home")) |
|
|
|
fmt.Fprint(w, pageBuilder(r, "home")) |
|
|
@ -103,7 +102,7 @@ func notFoundPage(w http.ResponseWriter, r *http.Request) { |
|
|
|
} |
|
|
|
} |
|
|
|
func card(title string, content string, footer string) string { |
|
|
|
func card(title string, content string, footer string) string { |
|
|
|
defer log.PanicSafe() |
|
|
|
defer log.PanicSafe() |
|
|
|
cardTemplate, err := ioutil.ReadFile("./static/card.tpl") |
|
|
|
cardTemplate, err := os.ReadFile("./static/card.tpl") |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.LogError("Unable to open card template") |
|
|
|
log.LogError("Unable to open card template") |
|
|
|
return "" |
|
|
|
return "" |
|
|
|