mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
* docs: audit, deploymentconfig, files, parameters * Swagger comments in workspacebuilds.go * structs in workspacebuilds.go * workspaceagents: instance identity * workspaceagents.go in progress * workspaceagents.go in progress * Agents * workspacebuilds.go * /workspaces * templates.go, templateversions.go * templateversion.go in progress * cancel * templateversions * wip * Merge * x-apidocgen * NullTime hack not needed anymore * Fix: x-apidocgen * Members * Fixes * Fix * WIP * WIP * Users * Logout * User profile * Status suspend activate * User roles * User tokens * Keys * SSH key * All * Typo * Fix * Entitlements * Groups * SCIM * Fix * Fix * Clean templates * Sort API pages * Fix: HashedSecret * General is first
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package codersdk
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"golang.org/x/xerrors"
|
|
)
|
|
|
|
type Replica struct {
|
|
// ID is the unique identifier for the replica.
|
|
ID uuid.UUID `json:"id" format:"uuid"`
|
|
// Hostname is the hostname of the replica.
|
|
Hostname string `json:"hostname"`
|
|
// CreatedAt is the timestamp when the replica was first seen.
|
|
CreatedAt time.Time `json:"created_at" format:"date-time"`
|
|
// RelayAddress is the accessible address to relay DERP connections.
|
|
RelayAddress string `json:"relay_address"`
|
|
// RegionID is the region of the replica.
|
|
RegionID int32 `json:"region_id"`
|
|
// Error is the replica error.
|
|
Error string `json:"error"`
|
|
// DatabaseLatency is the latency in microseconds to the database.
|
|
DatabaseLatency int32 `json:"database_latency"`
|
|
}
|
|
|
|
// Replicas fetches the list of replicas.
|
|
func (c *Client) Replicas(ctx context.Context) ([]Replica, error) {
|
|
res, err := c.Request(ctx, http.MethodGet, "/api/v2/replicas", nil)
|
|
if err != nil {
|
|
return nil, xerrors.Errorf("execute request: %w", err)
|
|
}
|
|
defer res.Body.Close()
|
|
|
|
if res.StatusCode != http.StatusOK {
|
|
return nil, readBodyAsError(res)
|
|
}
|
|
|
|
var replicas []Replica
|
|
return replicas, json.NewDecoder(res.Body).Decode(&replicas)
|
|
}
|