aboutsummaryrefslogtreecommitdiff
path: root/page/render.go
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2021-10-24 12:52:38 -0400
committerMitchell Riedstra <mitch@riedstra.dev>2021-10-24 12:52:38 -0400
commit268fcf7e6b671d4959a12111d5abf553bf0a201b (patch)
tree6f5c46c9a765478eaae78d66f4b9aefc953bbd1a /page/render.go
parentd36b6a55c8fa4400cd39de717443e110e990a8a3 (diff)
downloadgo-website-268fcf7e6b671d4959a12111d5abf553bf0a201b.tar.gz
go-website-268fcf7e6b671d4959a12111d5abf553bf0a201b.tar.xz
Redis caching. Linter config and cleanup.
Diffstat (limited to 'page/render.go')
-rw-r--r--page/render.go33
1 files changed, 19 insertions, 14 deletions
diff --git a/page/render.go b/page/render.go
index 07b1b88..6cbabf9 100644
--- a/page/render.go
+++ b/page/render.go
@@ -7,14 +7,14 @@ import (
)
// Render is a lower level option, allowing you to specify local
-// variables and the status code in which to return
+// variables and the status code in which to return.
func Render(w http.ResponseWriter, r *http.Request,
path string, vars map[string]interface{}, statusCode int) {
-
u := r.URL.Path
if u == "/" {
u = "/index"
}
+
u = filepath.Join(".", u)
// Sepcifically use the specified path for the page
@@ -32,8 +32,11 @@ func Render(w http.ResponseWriter, r *http.Request,
r.Method,
http.StatusNotFound,
u)
+
p = NewPage("404")
+
w.WriteHeader(http.StatusNotFound)
+
err := p.Render(w)
if err != nil {
Logger.Printf("%s %s path: %s while trying 404: %s",
@@ -43,19 +46,22 @@ func Render(w http.ResponseWriter, r *http.Request,
err)
http.Error(w, "Internal server error",
http.StatusInternalServerError)
+
return
}
- return
- } else {
- Logger.Printf("%s %s path: %s encountered: %s",
- r.RemoteAddr,
- r.Method,
- u,
- err)
- http.Error(w, "Internal server error",
- http.StatusInternalServerError)
+
return
}
+
+ Logger.Printf("%s %s path: %s encountered: %s",
+ r.RemoteAddr,
+ r.Method,
+ u,
+ err)
+ http.Error(w, "Internal server error",
+ http.StatusInternalServerError)
+
+ return
}
Logger.Printf("%s %s %d %s", r.RemoteAddr, r.Method, statusCode, u)
@@ -63,15 +69,14 @@ func Render(w http.ResponseWriter, r *http.Request,
// RenderWithVars allows you to specify a specific page and whether or not
// you wish to override vars. If left nil they will not be overridden.
-// Also see RenderForPath if you don't need to override them
+// Also see RenderForPath if you don't need to override them.
func RenderWithVars(w http.ResponseWriter, r *http.Request,
path string, vars map[string]interface{}) {
-
Render(w, r, path, vars, http.StatusOK)
}
// RenderForPath takes the path to a page and finish up the rendering
-// Allowing you to place logic on what page is rendered by your handlers
+// Allowing you to place logic on what page is rendered by your handlers.
func RenderForPath(w http.ResponseWriter, r *http.Request, path string) {
RenderWithVars(w, r, path, nil)
}