package sinks import ( "fmt" "gitea.maximumdirect.net/ejr/feedkit/config" ) // Factory constructs a sink instance from config. // // This is the mechanism that lets concrete daemons wire in whatever sinks they // want without main.go being full of switch statements. type Factory func(cfg config.SinkConfig) (Sink, error) type Registry struct { byDriver map[string]Factory } func NewRegistry() *Registry { return &Registry{byDriver: map[string]Factory{}} } func (r *Registry) Register(driver string, f Factory) { r.byDriver[driver] = f } func (r *Registry) Build(cfg config.SinkConfig) (Sink, error) { f, ok := r.byDriver[cfg.Driver] if !ok { return nil, fmt.Errorf("unknown sink driver: %q", cfg.Driver) } return f(cfg) }