remove superfluous use of ioutil

This commit is contained in:
Jimmy Zelinskie 2015-10-23 16:00:05 -04:00
parent 7cfa862f2c
commit d23b0167b6

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
} }