From 2914c403c990a0737bf482e8137a87b611ee7b57 Mon Sep 17 00:00:00 2001 From: Wizerd Date: Fri, 5 Jan 2024 22:18:16 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E4=BF=AE=E5=A4=8Darkose=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E6=A0=BC=E5=BC=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 3796279..740b039 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "os" "strconv" "time" + "strings" ) var redisClient *redis.Client @@ -87,22 +88,26 @@ func main() { router.POST("/api/arkose/token", func(c *gin.Context) { // 尝试从 Redis 获取一个 token - token, err := redisClient.RandomKey(ctx).Result() - if err != nil || token == "" { + key, err := redisClient.RandomKey(ctx).Result() + if err != nil || key == "" { c.JSON(http.StatusInternalServerError, gin.H{"error": "no token available"}) return } // 从 Redis 中删除获取到的 token - _, delErr := redisClient.Del(ctx, token).Result() + _, delErr := redisClient.Del(ctx, key).Result() if delErr != nil { fmt.Println("Error deleting token from Redis:", delErr) } + // 去除 "token:" 前缀 + token := strings.TrimPrefix(key, "token:") + // 返回获取到的 token c.JSON(http.StatusOK, gin.H{"token": token}) }) + router.Run(":8080") }