chore: fix tariff proxy creation
This commit is contained in:
parent
8d2b606043
commit
08f662ac91
1 changed files with 14 additions and 8 deletions
|
|
@ -19,8 +19,20 @@ func NewProxyFromConfig(ctx context.Context, typ string, other map[string]any) (
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateFeatures := func(f api.Feature) {
|
||||||
|
features := slices.DeleteFunc(embed.Features, func(feat api.Feature) bool {
|
||||||
|
return feat == f
|
||||||
|
})
|
||||||
|
|
||||||
|
if len(features) > 0 {
|
||||||
|
embed.Other["features"] = features
|
||||||
|
} else {
|
||||||
|
delete(embed.Other, "features")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if slices.Contains(embed.Features, api.Average) {
|
if slices.Contains(embed.Features, api.Average) {
|
||||||
embed.Other["features"] = sliceMinusElement(embed.Features, api.Average)
|
updateFeatures(api.Average)
|
||||||
t, err := NewFromConfig(ctx, typ, embed.Other)
|
t, err := NewFromConfig(ctx, typ, embed.Other)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -29,15 +41,9 @@ func NewProxyFromConfig(ctx context.Context, typ string, other map[string]any) (
|
||||||
}
|
}
|
||||||
|
|
||||||
if slices.Contains(embed.Features, api.Cacheable) {
|
if slices.Contains(embed.Features, api.Cacheable) {
|
||||||
embed.Other["features"] = sliceMinusElement(embed.Features, api.Cacheable)
|
updateFeatures(api.Cacheable)
|
||||||
return NewCachedFromConfig(ctx, typ, embed.Other)
|
return NewCachedFromConfig(ctx, typ, embed.Other)
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewFromConfig(ctx, typ, other)
|
return NewFromConfig(ctx, typ, other)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sliceMinusElement[T comparable](s []T, el T) []T {
|
|
||||||
return slices.DeleteFunc(s, func(f T) bool {
|
|
||||||
return el == f
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue