Use clousures for the http handlers

This commit is contained in:
Las Zenow 2012-08-15 13:58:16 +02:00
parent f1eab1bebc
commit 3db6231762
3 changed files with 54 additions and 48 deletions

View file

@ -42,16 +42,18 @@ func storeFile(r *http.Request) error {
return nil
}
func uploadHandler(coll *mgo.Collection, w http.ResponseWriter, r *http.Request) {
status := ""
if r.Method == "POST" {
err := storeFile(r)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
func uploadHandler(coll *mgo.Collection) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
status := ""
if r.Method == "POST" {
err := storeFile(r)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
status = "Upload successful."
}
status = "Upload successful."
}
loadTemplate(w, "upload", status)
loadTemplate(w, "upload", status)
}
}