fixed scan not being used correctly

This commit is contained in:
2021-10-07 21:21:49 +02:00
parent 2822aed294
commit 1fda101a35

View File

@@ -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) {