Merge pull request #91 from chihaya/tinyfix

remove superfluous use of ioutil
This commit is contained in:
Justin Li 2015-10-24 14:25:00 -04:00
commit a403392e76

View file

@ -6,7 +6,6 @@ package api
import ( import (
"encoding/json" "encoding/json"
"io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"runtime" "runtime"
@ -90,13 +89,8 @@ func (s *Server) getTorrent(w http.ResponseWriter, r *http.Request, p httprouter
} }
func (s *Server) putTorrent(w http.ResponseWriter, r *http.Request, p httprouter.Params) (int, error) { func (s *Server) putTorrent(w http.ResponseWriter, r *http.Request, p httprouter.Params) (int, error) {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return http.StatusInternalServerError, err
}
var torrent models.Torrent var torrent models.Torrent
err = json.Unmarshal(body, &torrent) err := json.NewDecoder(r.Body).Decode(&torrent)
if err != nil { if err != nil {
return http.StatusBadRequest, err return http.StatusBadRequest, err
} }
@ -129,13 +123,8 @@ func (s *Server) getUser(w http.ResponseWriter, r *http.Request, p httprouter.Pa
} }
func (s *Server) putUser(w http.ResponseWriter, r *http.Request, p httprouter.Params) (int, error) { func (s *Server) putUser(w http.ResponseWriter, r *http.Request, p httprouter.Params) (int, error) {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return http.StatusInternalServerError, err
}
var user models.User var user models.User
err = json.Unmarshal(body, &user) err := json.NewDecoder(r.Body).Decode(&user)
if err != nil { if err != nil {
return http.StatusBadRequest, err return http.StatusBadRequest, err
} }