Remove unique players route, update dependencies

This commit is contained in:
Jacob Gunther
2024-02-24 23:37:21 -06:00
parent 9926c09539
commit 16dde6347f
4 changed files with 30 additions and 97 deletions

View File

@@ -47,42 +47,6 @@ func (r *Redis) Connect(url string) error {
return nil
}
// Scan returns all keys by the pattern in the Redis database.
func (r *Redis) Scan(cursor uint64, pattern string, count int64) ([]string, uint64, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
res := r.Client.Scan(ctx, cursor, pattern, count)
if err := res.Err(); err != nil {
return nil, 0, err
}
return res.Result()
}
// GetString gets the value from Redis by the key and returns the value as a string.
func (r *Redis) GetString(key string) (string, bool, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
existsResult := r.Client.Exists(ctx, key)
if err := existsResult.Err(); err != nil {
return "", false, err
}
if existsResult.Val() == 0 {
return "", false, nil
}
result := r.Client.Get(ctx, key)
return result.Val(), true, result.Err()
}
// GetBytes gets the value from Redis by the key and returns the value as a byte array.
func (r *Redis) GetBytes(key string) ([]byte, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)

View File

@@ -4,7 +4,6 @@ import (
"fmt"
"net/http"
"strconv"
"strings"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
@@ -34,7 +33,6 @@ func init() {
}
app.Get("/ping", PingHandler)
app.Get("/list", ListHandler)
app.Get("/skin/:uuid", SkinHandler)
app.Get("/face/:uuid", FaceHandler)
app.Get("/head/:uuid", HeadHandler)
@@ -50,35 +48,6 @@ func PingHandler(ctx *fiber.Ctx) error {
return ctx.SendStatus(http.StatusOK)
}
// ListHandler is the API handler used for the `/list` route.
func ListHandler(ctx *fiber.Ctx) error {
result := make([]string, 0)
var (
cursor uint64 = 0
keys []string
err error
)
for {
keys, cursor, err = r.Scan(cursor, "unique:*", 25)
if err != nil {
return err
}
for _, uuid := range keys {
result = append(result, strings.TrimPrefix(uuid, "unique:"))
}
if cursor == 0 {
break
}
}
return ctx.JSON(result)
}
// SkinHandler is the API handler used for the `/skin/:uuid` route.
func SkinHandler(ctx *fiber.Ctx) error {
opts := ParseQueryParams(ctx, config.Routes.RawSkin)