mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
* 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
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package codersdk
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"golang.org/x/mod/semver"
|
|
)
|
|
|
|
// BuildInfoResponse contains build information for this instance of Coder.
|
|
type BuildInfoResponse struct {
|
|
// ExternalURL references the current Coder version.
|
|
// For production builds, this will link directly to a release. For development builds, this will link to a commit.
|
|
ExternalURL string `json:"external_url"`
|
|
// Version returns the semantic version of the build.
|
|
Version string `json:"version"`
|
|
}
|
|
|
|
// CanonicalVersion trims build information from the version.
|
|
// E.g. 'v0.7.4-devel+11573034' -> 'v0.7.4'.
|
|
func (b BuildInfoResponse) CanonicalVersion() string {
|
|
// We do a little hack here to massage the string into a form
|
|
// that works well with semver.
|
|
trimmed := strings.ReplaceAll(b.Version, "-devel+", "+devel-")
|
|
return semver.Canonical(trimmed)
|
|
}
|
|
|
|
// BuildInfo returns build information for this instance of Coder.
|
|
func (c *Client) BuildInfo(ctx context.Context) (BuildInfoResponse, error) {
|
|
res, err := c.Request(ctx, http.MethodGet, "/api/v2/buildinfo", nil)
|
|
if err != nil {
|
|
return BuildInfoResponse{}, err
|
|
}
|
|
defer res.Body.Close()
|
|
|
|
if res.StatusCode != http.StatusOK {
|
|
return BuildInfoResponse{}, readBodyAsError(res)
|
|
}
|
|
|
|
var buildInfo BuildInfoResponse
|
|
return buildInfo, json.NewDecoder(res.Body).Decode(&buildInfo)
|
|
}
|