2024-08-21 14:18:44 +05:30
|
|
|
package config
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
)
|
|
|
|
|
|
2025-01-20 17:45:33 +05:30
|
|
|
// NewProviderFunc is a function that creates a new provider.
|
|
|
|
|
type NewProviderFunc = func(ProviderConfig) Provider
|
2024-08-21 14:18:44 +05:30
|
|
|
|
2025-01-20 17:45:33 +05:30
|
|
|
// ProviderFactory is a factory that creates a new provider.
|
|
|
|
|
type ProviderFactory interface {
|
|
|
|
|
New(ProviderConfig) Provider
|
2024-08-21 14:18:44 +05:30
|
|
|
}
|
|
|
|
|
|
2025-01-20 17:45:33 +05:30
|
|
|
// NewProviderFactory creates a new provider factory.
|
|
|
|
|
func NewProviderFactory(f NewProviderFunc) ProviderFactory {
|
|
|
|
|
return &providerFactory{f: f}
|
2024-08-21 14:18:44 +05:30
|
|
|
}
|
|
|
|
|
|
2025-01-20 17:45:33 +05:30
|
|
|
// providerFactory is a factory that implements the ProviderFactory interface.
|
|
|
|
|
type providerFactory struct {
|
|
|
|
|
f NewProviderFunc
|
2024-08-21 14:18:44 +05:30
|
|
|
}
|
|
|
|
|
|
2025-01-20 17:45:33 +05:30
|
|
|
// New creates a new provider.
|
|
|
|
|
func (factory *providerFactory) New(config ProviderConfig) Provider {
|
|
|
|
|
return factory.f(config)
|
|
|
|
|
}
|
2024-08-21 14:18:44 +05:30
|
|
|
|
2025-01-20 17:45:33 +05:30
|
|
|
// ProviderConfig is the configuration for a provider.
|
|
|
|
|
type ProviderConfig struct{}
|
2024-08-21 14:18:44 +05:30
|
|
|
|
2025-01-20 17:45:33 +05:30
|
|
|
// Provider is an interface that represents a configuration provider.
|
|
|
|
|
type Provider interface {
|
|
|
|
|
// Get returns the configuration for the given URI.
|
|
|
|
|
Get(context.Context, Uri) (*Conf, error)
|
|
|
|
|
// Scheme returns the scheme of the provider.
|
|
|
|
|
Scheme() string
|
2024-08-21 14:18:44 +05:30
|
|
|
}
|