Skip to content

Instantly share code, notes, and snippets.

@jafstar
Created July 11, 2012 03:21
Show Gist options
  • Save jafstar/3087773 to your computer and use it in GitHub Desktop.
Save jafstar/3087773 to your computer and use it in GitHub Desktop.
Go http.Request
//"fmt"
"net/http"
//"html/template"
//"html"
//"net/url"
//"appengine"
//"appengine/channel"
//"appengine/user"
//"appengine/datastore"
//"appengine/mail"
//HOME
func home(w http.ResponseWriter, r *http.Request) {
/*fmt.Fprintln(w, r.Header )
fmt.Fprintln(w, r.Header.Get("Content-Type") )
fmt.Fprintln(w, r.Header.Get("X-AppEngine-Country"))
fmt.Fprintln(w, r.Header.Get("X-AppEngine-Region"))
fmt.Fprintln(w, r.Header.Get("X-AppEngine-City"))
fmt.Fprintln(w, r.Header.Get("X-AppEngine-CityLatLong"))
fmt.Fprintln(w, r.Header.Get("User-Agent") )
fmt.Fprintln(w, r.Method )
fmt.Fprintln(w, r.Host )
fmt.Fprintln(w, r.Method )*/
//fmt.Fprint(w, header,homepage,footer)
render(w, "home.html", nil)
}
//RENDER
func render(w http.ResponseWriter, file string, data map[string]string){
//TEMPLATE
view := template.Must(template.ParseFiles(
"templates/shell.html",
"templates/" + file,
))
//HEADER
w.Header().Set("Content-Type", "text/html")
//EXECUTE
err := view.Execute(w, data)
//ERROR
if err != nil {
fmt.Fprint(w, err)
}
}
//CHAT
func chat(w http.ResponseWriter, r *http.Request){
c := appengine.NewContext(r)
//u := user.Current(c)
key := "jafar12345"
tok, err := channel.Create(c, key)
if err != nil {
http.Error(w, "Couldn't create Channel", http.StatusInternalServerError)
c.Errorf("channel.Create: %v", err)
return
}
data := map[string]string{
"token": tok,
}
render(w, "chat.html", data)
}
//CONTACT
func contact(w http.ResponseWriter, r *http.Request){
//fmt.Fprint(w, header,contactpage,footer)
render(w, "contact.html", nil)
}
//THANKS
func thanks(w http.ResponseWriter, r *http.Request) {
//ERROR MAP
errorMap := map[string]string{}
//FORM MAP
formMap := map[string]string{
"Name": r.FormValue("name"),
"Email": r.FormValue("email"),
"Phone": r.FormValue("phone"),
"Message": r.FormValue("message"),
}
//CHECK FORM
errors := checkContactForm(formMap, errorMap)
//NO ERRORS
if len(errors) == 0 {
sendEmail(w,r,"[email protected]",formMap["msg"])
render(w, "thanks.html", nil)
//ERRORS
} else {
errors["errors"] = "true"
render(w, "error.html", errors)
}
//END
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment