From 3a40e7e080039f21a35f17bbc0a56cfb1abbb3b4 Mon Sep 17 00:00:00 2001 From: tcq Date: Thu, 27 Apr 2023 09:54:09 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9D=A1300ms=E4=BB=A5=E5=86=85=E7=9A=84?= =?UTF-8?q?=E9=9A=8F=E6=9C=BA=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/token-handler.go | 7 +++++++ main.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/handler/token-handler.go b/handler/token-handler.go index 54253b0..56fc235 100644 --- a/handler/token-handler.go +++ b/handler/token-handler.go @@ -2,7 +2,9 @@ package handler import ( "errors" + "math/rand" "net/http" + "time" "github.com/gin-gonic/gin" "myschools.me/campus/campus-core/campus" @@ -17,6 +19,11 @@ func TokenVerify(c *gin.Context) { reqid := campus.NewRequestID(nil) token := c.GetHeader("Authorization") + + source := rand.NewSource(time.Now().Unix()) + r := rand.New(source) + time.Sleep(time.Duration(r.Intn(300)) * time.Millisecond) + if token != "112233" { campus.RespBadRequest(c, "token err", errors.New("token err"), &reqid) } else { diff --git a/main.go b/main.go index e62f2b4..610a6f1 100644 --- a/main.go +++ b/main.go @@ -39,7 +39,7 @@ func main() { defer cancel() //取消注册 - err := consul.DeRegister(*appname, *addr, 8082) + err := consul.DeRegister(*appname, *addr, *port) if err != nil { fmt.Println("Error: ", err) }