Skip to content

Commit

Permalink
feat: add Inspect option to registry
Browse files Browse the repository at this point in the history
  • Loading branch information
alnr committed Apr 22, 2024
1 parent bd95ed2 commit 2013450
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion driver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"context"
"io/fs"

"github.com/pkg/errors"

"github.com/ory/hydra/v2/driver/config"
"github.com/ory/hydra/v2/fositex"
"github.com/ory/x/configx"
Expand All @@ -28,6 +30,7 @@ type (
extraMigrations []fs.FS
goMigrations []popx.Migration
fositexFactories []fositex.Factory
inspect func(Registry) error
}
OptionsModifier func(*options)

Expand Down Expand Up @@ -102,6 +105,12 @@ func WithExtraFositeFactories(f ...fositex.Factory) OptionsModifier {
}
}

func Inspect(f func(Registry) error) OptionsModifier {
return func(o *options) {
o.inspect = f
}
}

func New(ctx context.Context, sl *servicelocatorx.Options, opts []OptionsModifier) (Registry, error) {
o := newOptions()
for _, f := range opts {
Expand Down Expand Up @@ -152,6 +161,11 @@ func New(ctx context.Context, sl *servicelocatorx.Options, opts []OptionsModifie
CallRegistry(ctx, r)
}

c.Source(ctx).SetTracer(ctx, r.Tracer(ctx))
if o.inspect != nil {
if err := o.inspect(r); err != nil {
return nil, errors.WithStack(err)
}
}

return r, nil
}

0 comments on commit 2013450

Please sign in to comment.