diff options
Diffstat (limited to 'worker/handlers')
-rw-r--r-- | worker/handlers/register.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/worker/handlers/register.go b/worker/handlers/register.go new file mode 100644 index 00000000..5e8463e8 --- /dev/null +++ b/worker/handlers/register.go @@ -0,0 +1,27 @@ +package handlers + +import ( + "fmt" + + "git.sr.ht/~sircmpwn/aerc/worker/types" +) + +type FactoryFunc func(*types.Worker) (types.Backend, error) + +var workerFactories map[string]FactoryFunc = make(map[string]FactoryFunc) + +func RegisterWorkerFactory(scheme string, factory FactoryFunc) { + workerFactories[scheme] = factory +} + +func GetHandlerForScheme(scheme string, worker *types.Worker) (types.Backend, error) { + factory, ok := workerFactories[scheme] + if !ok { + return nil, fmt.Errorf("Unknown backend %s", scheme) + } + backend, err := factory(worker) + if err != nil { + return nil, err + } + return backend, nil +} |