mirror of
https://github.com/coder/coder.git
synced 2025-07-10 23:53:15 +00:00
- Deprecates the --experimental flag - Adds a new flag --experiments which supports passing multiple comma-separated values or a wildcard value. - Exposes a new endpoint /api/v2/experiments that returns the list of enabled experiments. - Deprecates the field Features.Experimental in favour of this new API. - Updates apidocgen to support type aliases (shoutout to @mtojek). - Modifies apitypings to support generating slice types. - Updates develop.sh to pass additional args after -- to $CODERD_SHIM.
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package codersdk
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
type Experiment string
|
|
|
|
const (
|
|
// ExperimentVSCodeLocal enables a workspace button to launch VSCode
|
|
// and connect using the local VSCode extension.
|
|
ExperimentVSCodeLocal Experiment = "vscode_local"
|
|
)
|
|
|
|
var (
|
|
// ExperimentsAll should include all experiments that are safe for
|
|
// users to opt-in to via --experimental='*'.
|
|
// Experiments that are not ready for consumption by all users should
|
|
// not be included here and will be essentially hidden.
|
|
ExperimentsAll = Experiments{
|
|
ExperimentVSCodeLocal,
|
|
}
|
|
)
|
|
|
|
// Experiments is a list of experiments that are enabled for the deployment.
|
|
// Multiple experiments may be enabled at the same time.
|
|
// Experiments are not safe for production use, and are not guaranteed to
|
|
// be backwards compatible. They may be removed or renamed at any time.
|
|
type Experiments []Experiment
|
|
|
|
func (e Experiments) Enabled(ex Experiment) bool {
|
|
for _, v := range e {
|
|
if v == ex {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (c *Client) Experiments(ctx context.Context) (Experiments, error) {
|
|
res, err := c.Request(ctx, http.MethodGet, "/api/v2/experiments", nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer res.Body.Close()
|
|
if res.StatusCode != http.StatusOK {
|
|
return nil, readBodyAsError(res)
|
|
}
|
|
var exp []Experiment
|
|
return exp, json.NewDecoder(res.Body).Decode(&exp)
|
|
}
|