Created
March 18, 2015 23:59
-
-
Save lettergram/1da6acd6db362392a033 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Shows user requested page | |
func viewHandler(w http.ResponseWriter, r *http.Request) { | |
// Parses URL to obtain title of file to add to .body | |
title := r.URL.Path[len("/"):] | |
// Load templatized page, given title | |
p, err := loadPage(title, r) | |
// If they do not have a cookie force them to login | |
if err != nil && !cookies.IsLoggedIn(r) { | |
http.Redirect(w, r, "/home", http.StatusFound) | |
return | |
// If they do have a cookie, they are logged in | |
} else if err != nil { | |
http.Redirect(w, r, "/login-succeeded", http.StatusFound) | |
return | |
} | |
// Generate template t | |
t, _ := template.ParseFiles("view.html") | |
// Write the template attributes of p (from load page) to t | |
t.Execute(w, p) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment