diff options
Diffstat (limited to 'page/render.go')
| -rw-r--r-- | page/render.go | 33 |
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) } |
