Skip to content

Instantly share code, notes, and snippets.

@calvinchengx
Created February 24, 2013 16:05
Show Gist options
  • Select an option

  • Save calvinchengx/5024347 to your computer and use it in GitHub Desktop.

Select an option

Save calvinchengx/5024347 to your computer and use it in GitHub Desktop.
package main
import (
"net/http"
)
func sign(w http.ResponseWriter, req *http.Request) {
if req.Method != "POST" {
http.NotFound(w, req)
return
}
entry := NewEntry()
entry.Name = req.FormValue("name")
entry.Message = req.FormValue("message")
if entry.Name == "" {
entry.Name = "Some dummy who forgot a name"
}
if entry.Message == "" {
entry.Message = "Some dummy who forgot a message"
}
s := session.Clone()
defer s.Close()
coll := s.DB("golangproject").C("entries")
if err := coll.Insert(entry); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
http.Redirect(w, req, "/", http.StatusTemporaryRedirect)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment