mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
* chore: rename `AgentConn` to `WorkspaceAgentConn` The codersdk was becoming bloated with consts for the workspace agent that made no sense to a reader. `Tailnet*` is an example of these consts. * chore: remove `Get` prefix from *Client functions * chore: remove `BypassRatelimits` option in `codersdk.Client` It feels wrong to have this as a direct option because it's so infrequently needed by API callers. It's better to directly modify headers in the two places that we actually use it. * Merge `appearance.go` and `buildinfo.go` into `deployment.go` * Merge `experiments.go` and `features.go` into `deployment.go` * Fix `make gen` referencing old type names * Merge `error.go` into `client.go` `codersdk.Response` lived in `error.go`, which is wrong. * chore: refactor workspace agent functions into agentsdk It was odd conflating the codersdk that clients should use with functions that only the agent should use. This separates them into two SDKs that are closely coupled, but separate. * Merge `insights.go` into `deployment.go` * Merge `organizationmember.go` into `organizations.go` * Merge `quota.go` into `workspaces.go` * Rename `sse.go` to `serversentevents.go` * Rename `codersdk.WorkspaceAppHostResponse` to `codersdk.AppHostResponse` * Format `.vscode/settings.json` * Fix outdated naming in `api.ts` * Fix app host response * Fix unsupported type * Fix imported type
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)
|
|
}
|