-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add variant strategy support #135
Conversation
Sonatype Lift is retiringSonatype Lift will be retiring on Sep 12, 2023, with its analysis stopping on Aug 12, 2023. We understand that this news may come as a disappointment, and Sonatype is committed to helping you transition off it seamlessly. If you’d like to retain your data, please export your issues from the web console. |
@@ -15,7 +15,7 @@ jobs: | |||
name: Checkout client specifications | |||
with: | |||
repository: Unleash/client-specification | |||
ref: refs/tags/v4.1.0 | |||
ref: refs/tags/v4.3.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update client spec to latest
api/feature.go
Outdated
} | ||
|
||
// Get variant for a given feature which is considered as enabled | ||
func (f Feature) GetVariant(ctx *context.Context) *Variant { | ||
if f.Enabled && len(f.Variants) > 0 { | ||
func (f VariantCollection) GetVariant(ctx *context.Context) *Variant { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of feature, now variant can be resolved from Strategy.
} | ||
|
||
// isEnabled abstracts away the details of checking if a toggle is turned on or off | ||
// without metrics | ||
func (uc *Client) isEnabled(feature string, options ...FeatureOption) (enabled bool) { | ||
func (uc *Client) isEnabled(feature string, options ...FeatureOption) api.StrategyResult { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of simple boolean, we are now returning complex object, that includes variant.
if s.Variants != nil && len(s.Variants) > 0 { | ||
groupIdValue := s.Parameters[strategy.ParamGroupId] | ||
groupId, ok := groupIdValue.(string) | ||
if !ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If strategy does not have groupId, then bad data and return disabled
}.GetVariant(ctx), | ||
} | ||
} else { | ||
return api.StrategyResult{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If strategy does not have variants, just return true and use old variants.
if len(f.Variants) == 0 { | ||
return defaultVariant | ||
} | ||
|
||
return f.GetVariant(ctx) | ||
return api.VariantCollection{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If code runs here, then strategy variants were not found, use old variants
No description provided.