coder/codersdk/updatecheck.go
Kyle Carberry 7ad87505c8 chore: move agent functions from codersdk into agentsdk (#5903)
* 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
2023-01-29 15:47:24 -06:00

35 lines
1.0 KiB
Go

package codersdk
import (
"context"
"encoding/json"
"net/http"
)
// UpdateCheckResponse contains information on the latest release of Coder.
type UpdateCheckResponse struct {
// Current indicates whether the server version is the same as the latest.
Current bool `json:"current"`
// Version is the semantic version for the latest release of Coder.
Version string `json:"version"`
// URL to download the latest release of Coder.
URL string `json:"url"`
}
// UpdateCheck returns information about the latest release version of
// Coder and whether or not the server is running the latest release.
func (c *Client) UpdateCheck(ctx context.Context) (UpdateCheckResponse, error) {
res, err := c.Request(ctx, http.MethodGet, "/api/v2/updatecheck", nil)
if err != nil {
return UpdateCheckResponse{}, err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return UpdateCheckResponse{}, ReadBodyAsError(res)
}
var buildInfo UpdateCheckResponse
return buildInfo, json.NewDecoder(res.Body).Decode(&buildInfo)
}