Guest User

Untitled

a guest
Mar 16th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.65 KB | None | 0 0
  1. package hello
  2.  
  3. import (
  4.     "appengine"
  5.     "appengine/user"
  6.     "http"
  7.     "template"
  8. )
  9.  
  10.  
  11. var baseTemplate = template.MustParseFile("base.html", nil)
  12.  
  13. func init() {
  14.     http.HandleFunc("/", handler)
  15. }
  16.  
  17. func handler(w http.ResponseWriter, r *http.Request) {
  18.     c := appengine.NewContext(r)
  19.     u := user.Current(c)
  20.    
  21.     if u == nil {
  22.         url, err := user.LoginURL(c, r.URL.String())
  23.         if err != nil {
  24.             http.Error(w, err.String(), http.StatusInternalServerError)
  25.             return
  26.         }
  27.         w.Header().Set("Location", url)
  28.         w.WriteHeader(http.StatusFound)
  29.         return
  30.     }
  31.    
  32.     baseTemplate.Execute(w, u)
  33. }
Add Comment
Please, Sign In to add comment