func findHero(db HeroDB, parms martini.Params, r render.Render) { u := (db).(*heroDB) id, _ := strconv.Atoi(parms["id"]) hero, ok := u.heros[id] if !ok { r.Error(http.StatusNotFound) return } r.JSON(http.StatusOK, hero) }
func updateHero(db HeroDB, req *http.Request, r render.Render) { u := (db).(*heroDB) breq := new(BatmanRequest) body, _ := ioutil.ReadAll(req.Body) req.Body.Close() err := json.Unmarshal(body, &breq) hero := breq.Hero if err != nil { r.Error(http.StatusInternalServerError) return } u.heros[hero.Id] = hero r.JSON(http.StatusOK, hero) }