Skip to content

Commit

Permalink
Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaanus committed Aug 2, 2023
1 parent 03914f5 commit 7c65044
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions api/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ func (fr FeatureResponse) SegmentsMap() map[int][]Constraint {
}

// Get variant for a given feature which is considered as enabled
func (f VariantCollection) GetVariant(ctx *context.Context) *Variant {
if len(f.Variants) > 0 {
v := f.getOverrideVariant(ctx)
func (vc VariantCollection) GetVariant(ctx *context.Context) *Variant {
if len(vc.Variants) > 0 {
v := vc.getOverrideVariant(ctx)
var variant *Variant
if v == nil {
variant = f.getVariantFromWeights(ctx)
variant = vc.getVariantFromWeights(ctx)
} else {
variant = &v.Variant
}
Expand All @@ -82,19 +82,19 @@ func (f VariantCollection) GetVariant(ctx *context.Context) *Variant {
return DISABLED_VARIANT
}

func (f VariantCollection) getVariantFromWeights(ctx *context.Context) *Variant {
func (vc VariantCollection) getVariantFromWeights(ctx *context.Context) *Variant {
totalWeight := 0
for _, variant := range f.Variants {
for _, variant := range vc.Variants {
totalWeight += variant.Weight
}
if totalWeight == 0 {
return DISABLED_VARIANT
}
stickiness := f.Variants[0].Stickiness
stickiness := vc.Variants[0].Stickiness

target := getNormalizedNumber(getSeed(ctx, stickiness), f.GroupId, totalWeight)
target := getNormalizedNumber(getSeed(ctx, stickiness), vc.GroupId, totalWeight)
counter := uint32(0)
for _, variant := range f.Variants {
for _, variant := range vc.Variants {
counter += uint32(variant.Weight)

if counter >= target {
Expand All @@ -104,8 +104,8 @@ func (f VariantCollection) getVariantFromWeights(ctx *context.Context) *Variant
return DISABLED_VARIANT
}

func (f VariantCollection) getOverrideVariant(ctx *context.Context) *VariantInternal {
for _, variant := range f.Variants {
func (vc VariantCollection) getOverrideVariant(ctx *context.Context) *VariantInternal {
for _, variant := range vc.Variants {
for _, override := range variant.Overrides {
if override.matchValue(ctx) {
variant.Overrides = nil
Expand Down

0 comments on commit 7c65044

Please sign in to comment.