summaryrefslogtreecommitdiff
path: root/golang/pkg
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--golang/pkg/api/ships.go22
-rw-r--r--golang/pkg/model/ship.go8
2 files changed, 14 insertions, 16 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
diff --git a/golang/pkg/model/ship.go b/golang/pkg/model/ship.go
index 549f09e..73244d4 100644
--- a/golang/pkg/model/ship.go
+++ b/golang/pkg/model/ship.go
@@ -1,15 +1,15 @@
package model
type Ship struct {
- Cargo Cargo `json:"cargo"`
- Cooldown Cooldown `json:"cooldown"`
+ Cargo *Cargo `json:"cargo"`
+ Cooldown *Cooldown `json:"cooldown"`
//// crew
//// engine
//// frame
- Fuel Fuel `json:"fuel"`
+ Fuel *Fuel `json:"fuel"`
//// modules
//// mounts
- Nav Nav `json:"nav"`
+ Nav *Nav `json:"nav"`
//// reactor
//registration: Registration;
Symbol string `json:"symbol"`