Documentation
¶
Overview ¶
Package helpers provides convenience helpers for common rule patterns
These helpers are NOT part of the core API - they're batteries-included examples showing how to consume the proposed package. You can use them as-is or as inspiration for your own custom rules
All helpers can be replicated using the core RuleFunc type directly ¶
Available helpers:
- MatchHintRule: Match a specific hint value
- MatchHintAnyRule: Match any of multiple hint values
- FallbackChainRule: Try multiple resolvers in order
- ConditionalRule: Custom predicate logic
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConditionalRule ¶
type ConditionalRule[T any, Output any, Config any] struct { // Predicate is called to determine if this rule matches Predicate func(context.Context) bool // Resolver is called when the predicate returns true to resolve the provider Resolver func(context.Context) (*eddy.ResolvedProvider[T, Output, Config], error) }
ConditionalRule creates a rule with a custom predicate
Example:
rule := &ConditionalRule[StorageClient, StorageCredentials, StorageConfig]{
Predicate: func(ctx context.Context) bool {
return auth.IsSystemAdmin(ctx)
},
Resolver: resolveAdminProvider,
}
type FallbackChainRule ¶
type FallbackChainRule[T any, Output any, Config any] struct { // Resolvers are tried in order until one succeeds Resolvers []func(context.Context) (*eddy.ResolvedProvider[T, Output, Config], error) }
FallbackChainRule tries resolvers in order until one succeeds
Example:
rule := &FallbackChainRule[StorageClient, StorageCredentials, StorageConfig]{
Resolvers: []func(context.Context) (*eddy.ResolvedProvider[StorageCredentials, StorageConfig], error){
resolveDatabaseCredentials,
resolveEnvCredentials,
resolveDefaultCredentials,
},
}
type MatchHintAnyRule ¶
type MatchHintAnyRule[T any, Output any, Config any, HintType ~string] struct { // Values are the acceptable hint values Values []HintType // Resolver is called when the hint matches any value to resolve the provider Resolver func(context.Context) (*eddy.ResolvedProvider[T, Output, Config], error) }
MatchHintAnyRule creates a rule that matches any of the provided hint values using typed strings from context
Example:
type ProviderHint string
rule := &MatchHintAnyRule[StorageClient, StorageCredentials, StorageConfig, ProviderHint]{
Values: []ProviderHint{"s3", "r2"},
Resolver: resolveObjectStorageProvider,
}
type MatchHintRule ¶
type MatchHintRule[T any, Output any, Config any, HintType ~string] struct { // Value is the expected hint value Value HintType // Resolver is called when the hint matches to resolve the provider Resolver func(context.Context) (*eddy.ResolvedProvider[T, Output, Config], error) }
MatchHintRule creates a rule that matches a hint value using typed strings from context
Example:
type ProviderHint string
rule := &MatchHintRule[StorageClient, StorageCredentials, StorageConfig, ProviderHint]{
Value: "s3",
Resolver: resolveS3Provider,
}