Issue 511 - Initial commit part 2

This commit is contained in:
Mayuresh Nirhali
2025-09-17 00:09:12 +05:30
parent 54ae426807
commit cc552e865e
5 changed files with 45 additions and 10 deletions

View File

@@ -8,4 +8,10 @@ import (
type RegistryLookup interface {
Lookup(ctx context.Context, req *model.Subscription) ([]model.Subscription, error)
Subscribe(ctx context.Context, subscription *model.Subscription) error
}
// RegistryLookupProvider initializes a new registry lookup instance.
type RegistryLookupProvider interface {
New(context.Context, map[string]string) (RegistryLookup, func() error, error)
}

View File

@@ -361,6 +361,27 @@ func (m *Manager) SimpleKeyManager(ctx context.Context, cache definition.Cache,
return km, nil
}
// Registry returns a RegistryLookup instance based on the provided configuration.
// It registers a cleanup function for resource management.
func (m *Manager) Registry(ctx context.Context, cfg *Config) (definition.RegistryLookup, error) {
rp, err := provider[definition.RegistryLookupProvider](m.plugins, cfg.ID)
if err != nil {
return nil, fmt.Errorf("failed to load provider for %s: %w", cfg.ID, err)
}
registry, closer, err := rp.New(ctx, cfg.Config)
if err != nil {
return nil, err
}
if closer != nil {
m.closers = append(m.closers, func() {
if err := closer(); err != nil {
panic(err)
}
})
}
return registry, nil
}
// Validator implements handler.PluginManager.
func (m *Manager) Validator(ctx context.Context, cfg *Config) (definition.SchemaValidator, error) {
panic("unimplemented")