Files
coder/codersdk/updatecheck.go
Marcin Tojek cfd02d959c docs: api root, buildinfo, csp (#5493)
* docs: Applications

* WIP

* WIP

* WIP

* Fix: consume

* Fix: @Description

* Fix

* docs: apiroot, buildinfo, csp

* Fix: buildinfo

* docs: updatecheck

* docs: apiroot

* Fix: s/none//g

* Fix: godoc nice

* Fix: description

* Fix: It

* Fix: code sample trim empty line

* More fixes

* Fix: br

* Merge

* Fix: no-security on updatecheck

* Fix: code tags

* Fix: enumerated values in code tags

* Rephrased

* Address PR comments

* Fix: URL, id

* Fix: array items

* Fix: any property

* Fix: array item singular
2022-12-22 15:53:14 +01: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)
}