You can define a custom strategy using multi.WithCustomStrategy combined with the multi.StrategyCustom constant. Because a strategy needs access to the underlying providers, you should use a StrategyConstructor to create a factory that closes over the providers.
When implementing, it is highly recommended to use the exposed Evaluate and BuildDefaultResult functions:
Evaluate: Use this to evaluate a single NamedProvider. It determines the evaluation type based on the defaultVal parameter.BuildDefaultResult: Use this when the strategy fails or encounters an error to return the appropriate default result.
Custom strategy signature:
StrategyFn[T FlagTypes] func(ctx context.Context, flag string, defaultValue T, flatCtx openfeature.FlattenedContext) openfeature.GenericResolutionDetail[T]
option := multi.WithCustomStrategy(func(providers []multi.NamedProvider) multi.StrategyFn[FlagTypes] {
return func[T FlagTypes](ctx context.Context, flag string, defaultValue T, flatCtx openfeature.FlattenedContext) openfeature.GenericResolutionDetail[T] {
// implementation
// ...
}
})