diff --git a/resolver/resolver.go b/resolver/resolver.go index ca6c8ed..5b551b1 100644 --- a/resolver/resolver.go +++ b/resolver/resolver.go @@ -16,6 +16,20 @@ type Resolver interface { isResolver() } +// ResolverFunc is a convenience type that implements the [Resolver] abstraction. +// +// This enables using normal function definitions to handle custom resolution. +type ResolverFunc func(context.Context, string) (any, error) + +// Resolve calls the underlying function to resolve the reference. +func (f ResolverFunc) Resolve(ctx context.Context, reference string) (any, error) { + return f(ctx, reference) +} + +func (ResolverFunc) isResolver() {} + +var _ Resolver = (*ResolverFunc)(nil) + // NoopResolver is a Resolver that does nothing. type NoopResolver struct { BaseResolver diff --git a/tracer/tracer.go b/tracer/tracer.go index cff1c3d..9479efe 100644 --- a/tracer/tracer.go +++ b/tracer/tracer.go @@ -21,6 +21,16 @@ type Tracer interface { Trace(name string, collection collection.Collection) error } +// TracerFunc is a convenience type that implements the [Tracer] abstraction. +// +// This enables using normal function definitions to handle custom tracing. +type TracerFunc func(string, collection.Collection) error + +// Trace calls the underlying function to trace the collection. +func (f TracerFunc) Trace(name string, collection collection.Collection) error { + return f(name, collection) +} + // NoopTracer is a Tracer that does nothing. type NoopTracer struct{}