mirror of
https://github.com/coder/coder.git
synced 2026-09-21 20:51:01 +08:00
This PR migrates 224 typed JSON response sites across 46 files to `codersdk.ReadBodyAsJSON`, so invalid 2xx bodies return structured errors while preserving URL credential redaction. It intentionally excludes agent-direct HTTP, Azure IMDS, `UseNumber`, and chat paths; stacked on coder/coder#27804, with chat and lint follow-ups in coder/coder#27858 and coder/coder#27859. Refs coder/coder#27044. Reviewed and updated by Coder Agents on behalf of @dylanhuff-at-coder.
34 lines
1007 B
Go
34 lines
1007 B
Go
package codersdk
|
|
|
|
import (
|
|
"context"
|
|
"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, ReadBodyAsJSON(res, &buildInfo)
|
|
}
|