title: Golang session based authentication
body: <p>I am trying to authenticate a user (using email and password) in golang but I am having some problems with sessions. It seems like I cant retrieve the session value from <strong>/login/</strong> to <strong>/</strong> (home) page. </p>
  
  <p><strong>User Registration</strong></p>
  
  <pre><code>hashedPassword, _ := bcrypt.GenerateFromPassword([]byte(r.Form["passwordSignup"][0]), bcrypt.DefaultCost)
  
  err = c.Insert(&amp;model.UserModel{
    Email:     r.Form["emailSignup"][0],
    Password:  string(hashedPassword),
    CreatedAt: time.Now(),
  })
  
  // TODO : should session management be made in here ???
  // you can use gorilla sessions if you want as far it works
  
  http.SetCookie(w, cookie)
  http.Redirect(w, r, "/", 301) // goes to the homepage(only accessed by authenticated users)
  </code></pre>
  
  <p><strong>Login</strong></p>
  
  <pre><code>if r.Form["emailLogin"][0] == result.Email 
  &amp;&amp; bcrypt.CompareHashAndPassword([]byte(result.Password), []byte(r.Form["passwordLogin"][0])) == nil {
  
    // TODO : Handling the session in here
  
    http.Redirect(w, r, "/", 301) // goes to the home page
  } else {
    http.Redirect(w, r, "/login/", 301)
  }
  </code></pre>
  
  <p>I checked this links too :
  <a href="http://shadynasty.biz/blog/2012/09/05/auth-and-sessions/" rel="nofollow">http://shadynasty.biz/blog/2012/09/05/auth-and-sessions/</a>
  <a href="https://www.youtube.com/watch?v=p0tGnjW_xxI" rel="nofollow">https://www.youtube.com/watch?v=p0tGnjW_xxI</a></p>