Skip to content

Instantly share code, notes, and snippets.

@Faliszek
Created March 28, 2018 08:57
Show Gist options
  • Save Faliszek/e4ca02cbbd35f165e1428dcc3c1ebc89 to your computer and use it in GitHub Desktop.
Save Faliszek/e4ca02cbbd35f165e1428dcc3c1ebc89 to your computer and use it in GitHub Desktop.
find box
//Find box
func Find(w http.ResponseWriter, r *http.Request) {
var result Box
id := bson.ObjectIdHex(mux.Vars(r)["id"])
err := db.Boxes.FindId(id).One(&result)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
log.Fatal(err)
}
//handleError in future
success, err := json.Marshal(result)
//Also handle this
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
log.Fatal(err)
}
w.Write(success)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment