blob: db5b7db47742e3e58a3369e1a19b0dfab3ef6488 (
plain)
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
|
package api
import (
"encoding/json"
"fmt"
"net/url"
)
type AgentMessage struct {
AccountID string `json:"accountId"`
Credits int `json:"credits"`
Headquarters string `json:"headquarters"`
ShipCount int `json:"shipCount"`
StartingFaction string `json:"startingFaction"`
Symbol string `json:"symbol"`
}
func (c *Client) MyAgent() (*AgentMessage, error) {
uriRef := url.URL{Path: "my/agent"}
msg, err := c.Send("GET", &uriRef, nil)
if err != nil {
return nil, err
}
if msg.Error != nil {
return nil, msg.Error
}
var response AgentMessage
if err := json.Unmarshal(msg.Data, &response); err != nil {
return nil, fmt.Errorf("failed to unmarshal agent data: %w", err)
}
return &response, nil
}
|