Skip to content

Commit

Permalink
[fix] 修复arkose输出格式的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Wizerd authored and Wizerd committed Jan 5, 2024
1 parent 1222509 commit 2914c40
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"strconv"
"time"
"strings"
)

var redisClient *redis.Client
Expand Down Expand Up @@ -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")
}

0 comments on commit 2914c40

Please sign in to comment.