Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions feature_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions featureflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ func SetFeatures(ctx context.Context, fts Features) context.Context {
return context.WithValue(ctx, featureContextID{}, fts)
}

func WithFeature(ctx context.Context, feature Feature) context.Context {
existingFeatures := GetFeatures(ctx)
if existingFeatures.IsActive(feature) {
return ctx
}
// clone existing features
features := make(Features, len(existingFeatures)+1)
copy(features, existingFeatures)
features[len(existingFeatures)] = byte(feature)
return SetFeatures(ctx, features)
}

func IsFeatureActive(ctx context.Context, f Feature) bool {
features := GetFeatures(ctx)
return features.IsActive(f)
}

// GetFeatures from a given context
func GetFeatures(ctx context.Context) Features {
f, ok := ctx.Value(featureContextID{}).(Features)
Expand Down
31 changes: 19 additions & 12 deletions features.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ Features:
idx: 12
start: v11.x
status: new, we still need to fix a few more tests
- id: UploadResultsV2
idx: 13
start: v12.x
status: new
8 changes: 7 additions & 1 deletion utils/featureflags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package main
import (
"flag"
"fmt"
"go/format"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -170,7 +171,12 @@ var AvailableFeatures = %ss{
out.WriteString("}\n")

if outPath != "" {
err := os.WriteFile(outPath, []byte(out.String()), 0o644)
fmtGoData, err := format.Source([]byte(out.String()))
if err != nil {
fmt.Fprintln(os.Stderr, "failed to format go code: "+err.Error())
os.Exit(1)
}
err = os.WriteFile(outPath, fmtGoData, 0o644)
if err != nil {
fmt.Fprintln(os.Stderr, "failed to write go code to "+outPath+": "+err.Error())
os.Exit(1)
Expand Down
Loading