Skip to content

Commit

Permalink
Fix API to be compatible with flagset, missed the comment initially (#…
Browse files Browse the repository at this point in the history
…7148)

Not breaking change, not released yet.

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Feb 7, 2023
1 parent 1ca481b commit e769012
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .chloggen/addvisit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ change_type: deprecation
component: featuregate

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate Registry.List in favor of Registry.Visit.
note: Deprecate Registry.List in favor of Registry.VisitAll.

# One or more tracking issues or pull requests related to the change
issues: [7041]
8 changes: 4 additions & 4 deletions featuregate/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ func (r *Registry) Set(id string, enabled bool) error {
return nil
}

// Visit visits the gates in lexicographical order, calling fn for each.
func (r *Registry) Visit(fn func(*Gate)) {
// VisitAll visits all the gates in lexicographical order, calling fn for each.
func (r *Registry) VisitAll(fn func(*Gate)) {
var gates []*Gate
r.gates.Range(func(key, value any) bool {
gates = append(gates, value.(*Gate))
Expand All @@ -169,10 +169,10 @@ func (r *Registry) Visit(fn func(*Gate)) {
}
}

// Deprecated: [v0.71.0] use Visit.
// Deprecated: [v0.71.0] use VisitAll.
func (r *Registry) List() []Gate {
var ret []Gate
r.Visit(func(gate *Gate) {
r.VisitAll(func(gate *Gate) {
ret = append(ret, *gate)
})
return ret
Expand Down
4 changes: 2 additions & 2 deletions featuregate/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ func TestGlobalRegistry(t *testing.T) {
func TestRegistry(t *testing.T) {
r := NewRegistry()
// Expect that no gates to visit.
r.Visit(func(gate *Gate) {
r.VisitAll(func(gate *Gate) {
t.FailNow()
})

const id = "foo"
g, err := r.Register(id, StageBeta, WithRegisterDescription("Test Gate"))
assert.NoError(t, err)
r.Visit(func(gate *Gate) {
r.VisitAll(func(gate *Gate) {
assert.Equal(t, id, gate.ID())
})
assert.True(t, g.IsEnabled())
Expand Down
2 changes: 1 addition & 1 deletion service/zpages.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func handleFeaturezRequest(w http.ResponseWriter, r *http.Request) {

func getFeaturesTableData() zpages.FeatureGateTableData {
data := zpages.FeatureGateTableData{}
featuregate.GlobalRegistry().Visit(func(gate *featuregate.Gate) {
featuregate.GlobalRegistry().VisitAll(func(gate *featuregate.Gate) {
data.Rows = append(data.Rows, zpages.FeatureGateTableRowData{
ID: gate.ID(),
Enabled: gate.IsEnabled(),
Expand Down

0 comments on commit e769012

Please sign in to comment.