mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
fix(multiplayer): bound adapter HTTP calls
This commit is contained in:
@@ -42,6 +42,8 @@ type Client struct {
|
||||
WorkloadTokenTTL time.Duration
|
||||
}
|
||||
|
||||
const DefaultHTTPTimeout = 10 * time.Second
|
||||
|
||||
type AllocatedServer struct {
|
||||
Allocation domain.Allocation
|
||||
Endpoint string
|
||||
@@ -108,9 +110,7 @@ func (c Client) RecoverAllocation(ctx context.Context, request domain.Allocation
|
||||
if request.AllocationID == "" || request.MatchID == "" || now.IsZero() {
|
||||
return AllocatedServer{}, false, domain.ErrAllocationInput
|
||||
}
|
||||
if c.HTTP == nil {
|
||||
c.HTTP = http.DefaultClient
|
||||
}
|
||||
c.HTTP = c.httpClient()
|
||||
base, err := c.endpoint()
|
||||
if err != nil {
|
||||
return AllocatedServer{}, false, err
|
||||
@@ -166,9 +166,7 @@ func (c Client) RecoverAllocation(ctx context.Context, request domain.Allocation
|
||||
// allocator registry. Compatibility fields must be present as Fleet labels;
|
||||
// malformed Ready objects fail closed instead of creating selectable capacity.
|
||||
func (c Client) ListReadyServers(ctx context.Context) ([]domain.ReadyServer, error) {
|
||||
if c.HTTP == nil {
|
||||
c.HTTP = http.DefaultClient
|
||||
}
|
||||
c.HTTP = c.httpClient()
|
||||
base, err := c.endpoint()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -213,9 +211,7 @@ func readyServerFromGameServer(name string, labels map[string]string) (domain.Re
|
||||
}
|
||||
|
||||
func (c Client) Allocate(ctx context.Context, request domain.AllocationRequest, labels map[string]string, now time.Time) (AllocatedServer, error) {
|
||||
if c.HTTP == nil {
|
||||
c.HTTP = http.DefaultClient
|
||||
}
|
||||
c.HTTP = c.httpClient()
|
||||
base, err := c.endpoint()
|
||||
if err != nil {
|
||||
return AllocatedServer{}, err
|
||||
@@ -305,6 +301,13 @@ func (c Client) endpoint() (string, error) {
|
||||
return strings.TrimRight(c.BaseURL, "/"), nil
|
||||
}
|
||||
|
||||
func (c Client) httpClient() *http.Client {
|
||||
if c.HTTP != nil {
|
||||
return c.HTTP
|
||||
}
|
||||
return &http.Client{Timeout: DefaultHTTPTimeout}
|
||||
}
|
||||
|
||||
func selectPort(ports []struct {
|
||||
Name string `json:"name"`
|
||||
Port int `json:"port"`
|
||||
|
||||
Reference in New Issue
Block a user