@@ 445,75 445,82 @@ func (fc *faceitChecker) requestHandler(w http.ResponseWriter, r *http.Request)
length := len(accountList)
for _, account := range accountList {
- player := &FaceitPlayer{}
- playerList = append(playerList, player)
-
- // parsed[0] is ID64 , parsed[1] is nickname
- parsed := strings.Split(account, "_")
- if len(parsed) != 2 {
- logger.Error("Failed to parse account",
- slog.String("account", account))
- continue
- }
+ select {
+ case <-r.Context().Done():
+ logger.Debug("Cancelled",
+ slog.String("error", r.Context().Err().Error()))
+ return
+ default:
+ player := &FaceitPlayer{}
+ playerList = append(playerList, player)
+
+ // parsed[0] is ID64 , parsed[1] is nickname
+ parsed := strings.Split(account, "_")
+ if len(parsed) != 2 {
+ logger.Error("Failed to parse account",
+ slog.String("account", account))
+ continue
+ }
- // Information is only needed if multiple accounts are displayed
- if length > 1 {
- player.SteamLink = "https://steamcommunity.com/profiles/" + parsed[0]
- player.SteamName = parsed[1]
- }
+ // Information is only needed if multiple accounts are displayed
+ if length > 1 {
+ player.SteamLink = "https://steamcommunity.com/profiles/" + parsed[0]
+ player.SteamName = parsed[1]
+ }
- playerLogger := logger.With(slog.String("ID", parsed[0]),
- slog.String("name", parsed[1]))
- playerLogger.Debug("Checking player")
+ playerLogger := logger.With(slog.String("ID", parsed[0]),
+ slog.String("name", parsed[1]))
+ playerLogger.Debug("Checking player")
- data, err := fc.getFaceitPlayer(r.Context(), parsed[0])
- if err != nil {
- playerLogger.Error("Failed to get Faceit player",
- slog.String("error", err.Error()))
- player.Error = err.Error()
- continue
- }
+ data, err := fc.getFaceitPlayer(r.Context(), parsed[0])
+ if err != nil {
+ playerLogger.Error("Failed to get Faceit player",
+ slog.String("error", err.Error()))
+ player.Error = err.Error()
+ continue
+ }
- var data2 faceitCSGO
- err = fc.checkStats(r.Context(), data.PlayerID, &data2)
- if err != nil {
- playerLogger.Error("Failed to check stats",
- slog.String("error", err.Error()))
- player.Error = err.Error()
- continue
- }
+ var data2 faceitCSGO
+ err = fc.checkStats(r.Context(), data.PlayerID, &data2)
+ if err != nil {
+ playerLogger.Error("Failed to check stats",
+ slog.String("error", err.Error()))
+ player.Error = err.Error()
+ continue
+ }
- banned, reason, err := fc.checkBan(r.Context(), data.PlayerID)
- if err != nil {
- playerLogger.Error("Failed to check ban status",
- slog.String("error", err.Error()))
- player.Error = err.Error()
- continue
- }
+ banned, reason, err := fc.checkBan(r.Context(), data.PlayerID)
+ if err != nil {
+ playerLogger.Error("Failed to check ban status",
+ slog.String("error", err.Error()))
+ player.Error = err.Error()
+ continue
+ }
- var status string
- if banned {
- status = fmt.Sprintf("Banned for %s on Faceit.", reason)
- } else {
- status = ""
- }
+ var status string
+ if banned {
+ status = fmt.Sprintf("Banned for %s on Faceit.", reason)
+ } else {
+ status = ""
+ }
- lastMatch, err := fc.lastMatch(r.Context(), data.PlayerID)
- if err != nil {
- playerLogger.Error("Failed to retrieve last match",
- slog.String("error", err.Error()))
- player.Error = err.Error()
- continue
- }
+ lastMatch, err := fc.lastMatch(r.Context(), data.PlayerID)
+ if err != nil {
+ playerLogger.Error("Failed to retrieve last match",
+ slog.String("error", err.Error()))
+ player.Error = err.Error()
+ continue
+ }
- player.Elo = data.Games.CSGO.Elo
- player.Kd = data2.Stats.KD
- player.Matches = data2.Stats.Matches
- player.Winrate = data2.Stats.Winrate
- player.Link = data.FaceitURL
- player.Status = status
- player.Country = data.Country
- player.LastMatch = lastMatch
+ player.Elo = data.Games.CSGO.Elo
+ player.Kd = data2.Stats.KD
+ player.Matches = data2.Stats.Matches
+ player.Winrate = data2.Stats.Winrate
+ player.Link = data.FaceitURL
+ player.Status = status
+ player.Country = data.Country
+ player.LastMatch = lastMatch
+ }
}
if err := fc.templates.ExecuteTemplate(w, "players.html", playerList); err != nil {