From ffc754f0abca0146f844cc10d91ce820bfdbc3b7 Mon Sep 17 00:00:00 2001 From: Derick M <58572875+TurtIeSocks@users.noreply.github.com> Date: Tue, 18 Apr 2023 00:10:51 -0400 Subject: [PATCH] remove deprecated - replace ioutil.ReadAll with json.NewDecoder - remove an unnecessary client log --- client/src/features/area/AreaExpand.tsx | 2 -- server/routes/auth.go | 11 ++++------- server/routes/proxy.go | 12 ++++-------- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/client/src/features/area/AreaExpand.tsx b/client/src/features/area/AreaExpand.tsx index ca72f88..9ecd309 100644 --- a/client/src/features/area/AreaExpand.tsx +++ b/client/src/features/area/AreaExpand.tsx @@ -15,8 +15,6 @@ export const AreaExpand = () => { body: JSON.stringify({ fence: record.geofence }), }).then((res) => res.json()), ) - - console.log(data) return (
diff --git a/server/routes/auth.go b/server/routes/auth.go index 7c0e65a..bb27cc5 100644 --- a/server/routes/auth.go +++ b/server/routes/auth.go @@ -3,7 +3,6 @@ package routes import ( "encoding/json" "flygon-admin/server/config" - "io/ioutil" "github.com/gin-gonic/gin" ) @@ -14,14 +13,12 @@ type Auth struct { } func Login(c *gin.Context) { - body, err := ioutil.ReadAll(c.Request.Body) - if err != nil { - c.JSON(500, gin.H{"error": err.Error()}) - return - } + + defer c.Request.Body.Close() var data Auth - err = json.Unmarshal(body, &data) + err := json.NewDecoder(c.Request.Body).Decode(&data) + if err != nil { c.JSON(500, gin.H{"error": err.Error()}) return diff --git a/server/routes/proxy.go b/server/routes/proxy.go index 2317d14..56c85fa 100644 --- a/server/routes/proxy.go +++ b/server/routes/proxy.go @@ -5,7 +5,6 @@ import ( "flygon-admin/server/config" "flygon-admin/server/util" "fmt" - "io/ioutil" "net/http" "strings" @@ -56,20 +55,17 @@ func buildRequest(dest string, c *gin.Context) (int, string, error) { return 500, fullUrl, err } - body, err := ioutil.ReadAll(res.Body) - if err != nil { - return res.StatusCode, fullUrl, err - } + defer res.Body.Close() // Types are not saved here since the request is just being proxied // Reference Flygon & Golbat repos for the full types - var data interface{} - err = json.Unmarshal(body, &data) + var body interface{} + err = json.NewDecoder(res.Body).Decode(&body) if err != nil { return res.StatusCode, fullUrl, err } - c.JSON(res.StatusCode, data) + c.JSON(res.StatusCode, body) return res.StatusCode, fullUrl, nil }