From c6cfaa59b0d5b005966355410abd745268a236e4 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Tue, 7 Nov 2023 11:35:00 +0300 Subject: fix: getplayersummaries cant unmarshal when player is in game (#131) --- backend/handlers/login.go | 10 +++++----- backend/models/models.go | 25 ++++--------------------- 2 files changed, 9 insertions(+), 26 deletions(-) (limited to 'backend') diff --git a/backend/handlers/login.go b/backend/handlers/login.go index 1a74166..a6e99bd 100644 --- a/backend/handlers/login.go +++ b/backend/handlers/login.go @@ -145,15 +145,15 @@ func DeleteCookie(c *gin.Context) { }) } -func GetPlayerSummaries(steamId, apiKey string) (*models.PlayerSummaries, error) { +func GetPlayerSummaries(steamId, apiKey string) (models.PlayerSummaries, error) { url := fmt.Sprintf("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=%s&steamids=%s", apiKey, steamId) resp, err := http.Get(url) if err != nil { - return nil, err + return models.PlayerSummaries{}, err } body, err := io.ReadAll(resp.Body) if err != nil { - return nil, err + return models.PlayerSummaries{}, err } type Result struct { @@ -163,7 +163,7 @@ func GetPlayerSummaries(steamId, apiKey string) (*models.PlayerSummaries, error) } var data Result if err := json.Unmarshal(body, &data); err != nil { - return nil, err + return models.PlayerSummaries{}, err } - return &data.Response.Players[0], err + return data.Response.Players[0], err } diff --git a/backend/models/models.go b/backend/models/models.go index 3aa2e9c..bf3ac86 100644 --- a/backend/models/models.go +++ b/backend/models/models.go @@ -122,25 +122,8 @@ type Pagination struct { } type PlayerSummaries struct { - SteamId string `json:"steamid"` - CommunityVisibilityState int `json:"communityvisibilitystate"` - ProfileState int `json:"profilestate"` - PersonaName string `json:"personaname"` - LastLogOff int `json:"lastlogoff"` - ProfileUrl string `json:"profileurl"` - Avatar string `json:"avatar"` - AvatarMedium string `json:"avatarmedium"` - AvatarFull string `json:"avatarfull"` - PersonaState int `json:"personastate"` - - CommentPermission int `json:"commentpermission"` - RealName string `json:"realname"` - PrimaryClanId string `json:"primaryclanid"` - TimeCreated int `json:"timecreated"` - LocCountryCode string `json:"loccountrycode"` - LocStateCode string `json:"locstatecode"` - LocCityId int `json:"loccityid"` - GameId int `json:"gameid"` - GameExtraInfo string `json:"gameextrainfo"` - GameServerIp string `json:"gameserverip"` + SteamId string `json:"steamid"` + PersonaName string `json:"personaname"` + AvatarFull string `json:"avatarfull"` + LocCountryCode string `json:"loccountrycode"` } -- cgit v1.2.3