Skip to content

Commit

Permalink
add json tags to struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Hopertz committed Sep 1, 2024
1 parent 37d6ece commit c3204da
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions cmd/api/leaderboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ type Member struct {
}

type Data struct {
Username string
Rating int
Username string `json:"username"`
Rating int `json:"rating"`
}

const user_url = "https://lichess.org/api/users"
Expand Down Expand Up @@ -69,8 +69,8 @@ func (app *application) leaderboardHandler(c echo.Context) error {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": "internal server error"})
}

rapid := []Data{}
blitz := []Data{}
rapid := []Data{}
blitz := []Data{}

for _, user := range members {
if !user.Disabled {
Expand All @@ -80,13 +80,13 @@ func (app *application) leaderboardHandler(c echo.Context) error {

}

sort.Slice(rapid, func(i, j int) bool {
return rapid[i].Rating > rapid[j].Rating
})
sort.Slice(rapid, func(i, j int) bool {
return rapid[i].Rating > rapid[j].Rating
})

sort.Slice(blitz, func(i, j int) bool {
return blitz[i].Rating > blitz[j].Rating
})
sort.Slice(blitz, func(i, j int) bool {
return blitz[i].Rating > blitz[j].Rating
})

summary := make(map[string][]Data)
summary["rapid"] = rapid
Expand Down

0 comments on commit c3204da

Please sign in to comment.