Skip to content

Commit

Permalink
fix: not ndjson , normal json
Browse files Browse the repository at this point in the history
  • Loading branch information
Hopertz committed Sep 1, 2024
1 parent a318842 commit 7c1591b
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions cmd/api/leaderboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"fmt"
"io"
"log/slog"
"net/http"
"sort"
Expand Down Expand Up @@ -34,7 +33,6 @@ type KeyValue struct {

const user_url = "https://lichess.org/api/users"


func (app *application) leaderboardHandler(c echo.Context) error {

members_ids, err := app.store.GetLichessTeamMembers(c.Request().Context())
Expand Down Expand Up @@ -64,26 +62,11 @@ func (app *application) leaderboardHandler(c echo.Context) error {

defer resp.Body.Close()

res := json.NewDecoder(resp.Body)

var members []Member

for {

var member Member
err := res.Decode(&member)
if err != nil {
if err != io.EOF {
slog.Error("we got an error while reading body", "err", err)
return c.JSON(http.StatusInternalServerError, map[string]string{"error": "internal server error"})
}

break

}

members = append(members, member)

err = json.NewDecoder(resp.Body).Decode(&members)
if err != nil {
slog.Error("error while reading bod (users)", "err", err)
return c.JSON(http.StatusInternalServerError, map[string]string{"error": "internal server error"})
}

summary := make(map[string]map[string]int)
Expand Down

0 comments on commit 7c1591b

Please sign in to comment.