Created
March 28, 2018 08:57
-
-
Save Faliszek/e4ca02cbbd35f165e1428dcc3c1ebc89 to your computer and use it in GitHub Desktop.
find box
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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