From 1fda101a3586138d7228a59b59e9989f977c5f75 Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Thu, 7 Oct 2021 21:21:49 +0200 Subject: [PATCH] fixed scan not being used correctly --- utils/utils.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/utils/utils.go b/utils/utils.go index 989e998..e7f748c 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -100,7 +100,7 @@ func SendJSON(data interface{}, w http.ResponseWriter) error { } func GetMatchStats(db *ent.Client, lock *sync.RWMutex, player *ent.Player) (int, int, int, error) { - var v struct { + var v []struct { Wins int `json:"wins"` Ties int `json:"ties"` Total int `json:"total"` @@ -140,7 +140,11 @@ func GetMatchStats(db *ent.Client, lock *sync.RWMutex, player *ent.Player) (int, return 0, 0, 0, err } - return v.Wins, v.Ties, v.Total - v.Wins - v.Ties, nil + if len(v) < 1 { + return 0, 0, 0, nil + } + + return v[0].Wins, v[0].Ties, v[0].Total - v[0].Wins - v[0].Ties, nil } func IsAuthCodeValid(player *ent.Player, lock *sync.RWMutex, apiKey string, shareCode string, authCode string, rl ratelimit.Limiter) (bool, error) {