From 7fed1bbdcdf789641af2777e12288e818ec12a20 Mon Sep 17 00:00:00 2001 From: Jianhui Zhao Date: Sun, 28 Feb 2021 20:40:27 +0800 Subject: [PATCH] Improve code Signed-off-by: Jianhui Zhao --- http.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/http.go b/http.go index 793941f..7ce000f 100644 --- a/http.go +++ b/http.go @@ -12,7 +12,6 @@ import ( "time" "github.com/gin-gonic/gin" - jsoniter "github.com/json-iterator/go" _ "github.com/mattn/go-sqlite3" "github.com/rs/zerolog/log" "github.com/zhaojh329/rttys/cache" @@ -21,8 +20,8 @@ import ( ) type credentials struct { - Password string `json:"password"` Username string `json:"username"` + Password string `json:"password"` } var httpSessions *cache.Cache @@ -204,7 +203,7 @@ func httpStart(br *broker) { r.POST("/signin", func(c *gin.Context) { var creds credentials - err := jsoniter.NewDecoder(c.Request.Body).Decode(&creds) + err := c.BindJSON(&creds) if err != nil { c.Status(http.StatusBadRequest) return @@ -248,7 +247,7 @@ func httpStart(br *broker) { r.POST("/signup", func(c *gin.Context) { var creds credentials - err := jsoniter.NewDecoder(c.Request.Body).Decode(&creds) + err := c.BindJSON(&creds) if err != nil { c.Status(http.StatusBadRequest) return