helpers

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 10, 2025 License: Apache-2.0 Imports: 5 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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,
}

func (*ConditionalRule[T, Output, Config]) Evaluate

func (r *ConditionalRule[T, Output, Config]) Evaluate(ctx context.Context) mo.Option[eddy.Result[T, Output, Config]]

Evaluate implements Rule.Evaluate

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,
    },
}

func (*FallbackChainRule[T, Output, Config]) Evaluate

func (r *FallbackChainRule[T, Output, Config]) Evaluate(ctx context.Context) mo.Option[eddy.Result[T, Output, Config]]

Evaluate implements Rule.Evaluate

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,
}

func (*MatchHintAnyRule[T, Output, Config, HintType]) Evaluate

func (r *MatchHintAnyRule[T, Output, Config, HintType]) Evaluate(ctx context.Context) mo.Option[eddy.Result[T, Output, Config]]

Evaluate implements Rule.Evaluate

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,
}

func (*MatchHintRule[T, Output, Config, HintType]) Evaluate

func (r *MatchHintRule[T, Output, Config, HintType]) Evaluate(ctx context.Context) mo.Option[eddy.Result[T, Output, Config]]

Evaluate implements Rule.Evaluate

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL