diff --git a/golang/pkg/agent/navigate.go b/golang/pkg/agent/navigate.go index 14d2e93..9aa6e63 100644 --- a/golang/pkg/agent/navigate.go +++ b/golang/pkg/agent/navigate.go @@ -55,10 +55,7 @@ func (a *agent) shortestPath(origin string, destination string, fuelCapacity int unvisited[waypoints[i].Symbol] = &waypoints[i] // We need to know which waypoints allow refueling waypoints[i].Traits = slices.DeleteFunc(waypoints[i].Traits, func(trait model.Common) bool { - if trait.Symbol == "MARKETPLACE" { - return false - } - return true + return trait.Symbol != "MARKETPLACE" }) if len(waypoints[i].Traits) > 0 { market, err := a.client.GetMarket(symbol, a.ships) @@ -66,16 +63,10 @@ func (a *agent) shortestPath(origin string, destination string, fuelCapacity int return nil, 0, fmt.Errorf("failed to get market %s: %w", symbol, err) } market.Exchange = slices.DeleteFunc(market.Exchange, func(item model.Common) bool { - if item.Symbol == "FUEL" { - return false - } - return true + return item.Symbol != "FUEL" }) market.Exports = slices.DeleteFunc(market.Exports, func(item model.Common) bool { - if item.Symbol == "FUEL" { - return false - } - return true + return item.Symbol != "FUEL" }) if len(market.Exchange) == 0 && len(market.Exports) == 0 { waypoints[i].Traits = nil diff --git a/golang/pkg/api/api.go b/golang/pkg/api/api.go index 6520251..28b45f5 100644 --- a/golang/pkg/api/api.go +++ b/golang/pkg/api/api.go @@ -196,7 +196,7 @@ func (c *Client) sendOne(method string, uri *url.URL, payload any) (*APIMessage, select { case <-c.ctx.Done(): return nil, fmt.Errorf("failed to sendOne: ctx cancelled") - case <-time.After(e.RetryAfter.Duration() * time.Second): + case <-time.After(time.Until(e.Reset)): } return c.sendOne(method, uri, payload) } diff --git a/golang/pkg/api/errors.go b/golang/pkg/api/errors.go index 2e36f16..c5a5310 100644 --- a/golang/pkg/api/errors.go +++ b/golang/pkg/api/errors.go @@ -19,7 +19,7 @@ type RateLimitError struct { func decodeRateLimitError(msg json.RawMessage) RateLimitError { var e RateLimitError if err := json.Unmarshal(msg, &e); err != nil { - panic(fmt.Errorf("Failed to decode iapi error code 429 RateLimitError: %v, %w", msg, err)) + panic(fmt.Errorf("failed to decode iapi error code 429 RateLimitError: %v, %w", msg, err)) } return e } @@ -36,7 +36,7 @@ type ShipInTransitError struct { func decodeShipInTransitError(msg json.RawMessage) ShipInTransitError { var e ShipInTransitError if err := json.Unmarshal(msg, &e); err != nil { - panic(fmt.Errorf("Failed to decode api error code 4214 ShipInTransitError: %v, %w", msg, err)) + panic(fmt.Errorf("failed to decode api error code 4214 ShipInTransitError: %v, %w", msg, err)) } return e } diff --git a/golang/pkg/api/ships.go b/golang/pkg/api/ships.go index fe1770b..3bb0ec3 100644 --- a/golang/pkg/api/ships.go +++ b/golang/pkg/api/ships.go @@ -59,7 +59,7 @@ func (c *Client) Navigate(s *model.Ship, waypointSymbol string) error { select { case <-c.ctx.Done(): return fmt.Errorf("failed: context cancelled") - case <-time.After(s.Nav.Route.Arrival.Sub(time.Now())): + case <-time.After(time.Until(s.Nav.Route.Arrival)): } s.Nav.Status = "IN_ORBIT" return nil