summaryrefslogtreecommitdiff
path: root/golang/pkg/api/ships.go
diff options
context:
space:
mode:
authorJulien Dessaux2025-02-12 23:43:52 +0100
committerJulien Dessaux2025-02-12 23:43:52 +0100
commit23dd8f4a27de640d4f1cb85c5794799d53af9237 (patch)
tree9bf88af1839155f61873fd9916c8774adc64a592 /golang/pkg/api/ships.go
parent[golang] updated go.mod (diff)
downloadspacetraders-23dd8f4a27de640d4f1cb85c5794799d53af9237.tar.gz
spacetraders-23dd8f4a27de640d4f1cb85c5794799d53af9237.tar.bz2
spacetraders-23dd8f4a27de640d4f1cb85c5794799d53af9237.zip
[golang] refactor ships api
Diffstat (limited to '')
-rw-r--r--golang/pkg/api/ships.go22
1 files changed, 10 insertions, 12 deletions
diff --git a/golang/pkg/api/ships.go b/golang/pkg/api/ships.go
index 9e9797a..08d41ac 100644
--- a/golang/pkg/api/ships.go
+++ b/golang/pkg/api/ships.go
@@ -5,6 +5,7 @@ import (
"net/url"
"path"
+ "git.adyxax.org/adyxax/spacetraders/golang/pkg/agent"
"git.adyxax.org/adyxax/spacetraders/golang/pkg/model"
)
@@ -12,13 +13,12 @@ func (c *Client) Dock(s *model.Ship) error {
if s.Nav.Status == "DOCKED" {
return nil
}
+ uriRef := url.URL{Path: path.Join("my/ships", s.Symbol, "dock")}
type DockResponse struct {
- Nav model.Nav `json:"nav"`
+ Nav *model.Nav `json:"nav"`
}
- uriRef := url.URL{Path: path.Join("my/ships", s.Symbol, "dock")}
var response DockResponse
- err := c.Send("POST", &uriRef, nil, &response)
- if err != nil {
+ if err := c.Send("POST", &uriRef, nil, &response); err != nil {
return fmt.Errorf("failed to dock ship %s: %w", s.Symbol, err)
}
s.Nav = response.Nav
@@ -27,25 +27,23 @@ func (c *Client) Dock(s *model.Ship) error {
func (c *Client) MyShips() ([]model.Ship, error) {
uriRef := url.URL{Path: "my/ships"}
- var response []model.Ship
- err := c.Send("GET", &uriRef, nil, &response)
- if err != nil {
+ var ships []model.Ship
+ if err := c.Send("GET", &uriRef, nil, &ships); err != nil {
return nil, fmt.Errorf("failed to get ships: %w", err)
}
- return response, nil
+ return ships, nil
}
func (c *Client) Orbit(s *model.Ship) error {
if s.Nav.Status == "IN_ORBIT" {
return nil
}
+ uriRef := url.URL{Path: path.Join("my/ships", s.Symbol, "orbit")}
type OrbitResponse struct {
- Nav model.Nav `json:"nav"`
+ Nav *model.Nav `json:"nav"`
}
- uriRef := url.URL{Path: path.Join("my/ships", s.Symbol, "orbit")}
var response OrbitResponse
- err := c.Send("POST", &uriRef, nil, &response)
- if err != nil {
+ if err := c.Send("POST", &uriRef, nil, &response); err != nil {
return fmt.Errorf("failed to orbit ship %s: %w", s.Symbol, err)
}
s.Nav = response.Nav