feat(feature): add NewBooleanGate convenience constructor#144
Merged
Conversation
NewBooleanGate(enabled) is shorthand for NewVersionGate("", nil).When(enabled):
a gate with no version constraints whose result is driven solely by a boolean.
It expresses flag-toggled mutations and resources more directly than spelling out
an empty version gate, and still returns a *VersionGate so further conditions
compose with When.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a small convenience constructor feature.NewBooleanGate(enabled bool) that wraps the common NewVersionGate("", nil).When(enabled) pattern, with accompanying unit tests.
Changes:
- New exported
NewBooleanGateconstructor inpkg/feature/feature.go. - Table-driven tests plus a chaining test verifying composition with
When.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/feature/feature.go | Adds NewBooleanGate shorthand returning *VersionGate. |
| pkg/feature/feature_test.go | Adds enabled/disabled table tests and a chainability test. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds
feature.NewBooleanGate(enabled bool), a convenience constructor for a gate driven purely by a boolean. It is shorthand forfeature.NewVersionGate("", nil).When(enabled), the form operators reach for whenever a mutation or resource is toggled by a spec flag rather than an application version. The explicit empty-version spelling is easy to mistype and reads obscurely, so this gives that common case a direct, well-named constructor.Changes
feature.NewBooleanGate(enabled bool) *VersionGate: a gate with no version constraints whose result is driven solely by the boolean. It returns*VersionGate, so additional conditions still compose viaWhen.Related
Documentation and examples adopt the new constructor separately, on the docs site branch.
Testing
New table tests cover the enabled and disabled results and confirm that further
Whenconditions still compose on the returned gate.go test ./pkg/feature/...passes, andgo build ./...,make build-examples, andgolangci-lint run ./pkg/feature/...(0 issues) are all clean.