Skip to content

Commit

Permalink
Add func definitions for resolver and tracer
Browse files Browse the repository at this point in the history
This adds some basic convenience types to make working with these
new types and abstractions easier.
  • Loading branch information
bitwizeshift committed Jul 8, 2024
1 parent 5f2aca4 commit 1e6fbda
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down

0 comments on commit 1e6fbda

Please sign in to comment.