feat: add port-sharing backend (#11939)

This commit is contained in:
Garrett Delfosse
2024-02-13 09:31:20 -05:00
committed by GitHub
parent c939416702
commit 3ab3a62bef
48 changed files with 1947 additions and 59 deletions

View File

@ -0,0 +1,23 @@
package httpmw
import (
"fmt"
"net/http"
"github.com/coder/coder/v2/coderd/httpapi"
"github.com/coder/coder/v2/codersdk"
)
func RequireExperiment(experiments codersdk.Experiments, experiment codersdk.Experiment) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !experiments.Enabled(experiment) {
httpapi.Write(r.Context(), w, http.StatusForbidden, codersdk.Response{
Message: fmt.Sprintf("Experiment '%s' is required but not enabled", experiment),
})
return
}
next.ServeHTTP(w, r)
})
}
}