Documentation
¶
Index ¶
- func RunWithTimeout(ctx context.Context, timeout time.Duration, fn func(ctx context.Context) error) error
- type Discovery
- func (d *Discovery) Call(v any, name string, args ...any) ([]any, error)
- func (d *Discovery) CallWithContext(ctx context.Context, v any, name string, args ...any) ([]any, error)
- func (d *Discovery) Discover(v any, prefix string) []MethodInfo
- func (d *Discovery) DiscoverAll(v any, prefixes ...string) map[string][]MethodInfo
- func (d *Discovery) HasMethod(v any, name string) bool
- type HookFunc
- type MethodInfo
- type Runner
- func (r *Runner) After(key string, fn HookFunc)
- func (r *Runner) AfterAll(fn HookFunc)
- func (r *Runner) Before(key string, fn HookFunc)
- func (r *Runner) BeforeAll(fn HookFunc)
- func (r *Runner) Clear()
- func (r *Runner) Discovery() *Discovery
- func (r *Runner) Run(ctx context.Context, key string, action func() error, args ...any) error
- func (r *Runner) RunParallel(ctx context.Context, key string, args ...any) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Discovery ¶
type Discovery struct {
// contains filtered or unexported fields
}
Discovery finds lifecycle methods on structs via reflection.
Example:
d := hooks.NewDiscovery() methods := d.Discover(myService, "OnStart")
func NewDiscovery ¶
func NewDiscovery() *Discovery
NewDiscovery creates a hook discovery instance with caching.
func (*Discovery) CallWithContext ¶
func (d *Discovery) CallWithContext(ctx context.Context, v any, name string, args ...any) ([]any, error)
CallWithContext invokes a method with context as first argument.
func (*Discovery) Discover ¶
func (d *Discovery) Discover(v any, prefix string) []MethodInfo
Discover finds all methods on v with the given prefix.
Returns:
A list of discovered matching methods.
func (*Discovery) DiscoverAll ¶
func (d *Discovery) DiscoverAll(v any, prefixes ...string) map[string][]MethodInfo
DiscoverAll finds methods matching any of the given prefixes.
type MethodInfo ¶
MethodInfo holds information about a discovered method.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner manages execution of lifecycle hooks with before/after patterns.
func NewRunner ¶
func NewRunner() *Runner
NewRunner creates a hook runner with a shared discovery instance.
func (*Runner) RunParallel ¶ added in v1.0.0
RunParallel executes hooks concurrently. Each hook runs in its own goroutine. If any hook returns an error, cancellation is propagated via context.
Example:
err := r.RunParallel(ctx, "my-event", args)