diff options
author | Reto Brunner <reto@labrat.space> | 2019-07-18 06:25:42 +0200 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-07-19 15:37:55 -0400 |
commit | 6fed04bb9fa43d3886d47d0c845d32fff11569b5 (patch) | |
tree | 461c8086c06236761555f08a614f88d7c058523b /worker/handlers/register.go | |
parent | 66a9052f0fa8d2caf0d82435241b10e9ba8665b2 (diff) | |
download | aerc-6fed04bb9fa43d3886d47d0c845d32fff11569b5.tar.gz |
Register worker in init.
This allows backends which can't always be compiled due to missing
dependencies (say libnotmuch) to be compiled conditionally with buildflags.
Diffstat (limited to 'worker/handlers/register.go')
-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 +} |