forked from solovev/steam_go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.go
55 lines (50 loc) · 1.68 KB
/
player.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package steam_auth
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
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 int `json:"loccountrycode"`
LocStateCode int `json:"locstatecode"`
LocCityId int `json:"loccityid"`
GameId int `json:"gameid"`
GameExtraInfo string `json:"gameextrainfo"`
GameServerIp string `json:"gameserverip"`
}
func GetPlayerSummaries(steamId, apiKey string) (*PlayerSummaries, error) {
url := fmt.Sprintf("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=%s&steamids=%s", apiKey, steamId)
resp, err := http.Get(url)
if err != nil {
return nil, err
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
type Result struct {
Response struct {
Players []PlayerSummaries `json:"players"`
} `json:"response"`
}
var data Result
if err := json.Unmarshal(body, &data); err != nil {
return nil, err
}
return &data.Response.Players[0], err
}