aboutsummaryrefslogtreecommitdiffstats
path: root/worker/worker.go
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2019-07-18 06:25:42 +0200
committerDrew DeVault <sir@cmpwn.com>2019-07-19 15:37:55 -0400
commit6fed04bb9fa43d3886d47d0c845d32fff11569b5 (patch)
tree461c8086c06236761555f08a614f88d7c058523b /worker/worker.go
parent66a9052f0fa8d2caf0d82435241b10e9ba8665b2 (diff)
downloadaerc-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/worker.go')
-rw-r--r--worker/worker.go24
1 files changed, 7 insertions, 17 deletions
diff --git a/worker/worker.go b/worker/worker.go
index a37927e7..f1f47c38 100644
--- a/worker/worker.go
+++ b/worker/worker.go
@@ -1,14 +1,13 @@
package worker
import (
- "git.sr.ht/~sircmpwn/aerc/worker/imap"
- "git.sr.ht/~sircmpwn/aerc/worker/maildir"
- "git.sr.ht/~sircmpwn/aerc/worker/types"
-
"fmt"
"log"
"net/url"
"strings"
+
+ "git.sr.ht/~sircmpwn/aerc/worker/handlers"
+ "git.sr.ht/~sircmpwn/aerc/worker/types"
)
// Guesses the appropriate worker type based on the given source string
@@ -23,19 +22,10 @@ func NewWorker(source string, logger *log.Logger) (*types.Worker, error) {
scheme = scheme[:strings.IndexRune(scheme, '+')]
fmt.Println(scheme)
}
- switch scheme {
- case "imap":
- fallthrough
- case "imaps":
- worker.Backend = imap.NewIMAPWorker(worker)
- case "maildir":
- if w, err := maildir.NewWorker(worker); err != nil {
- return nil, fmt.Errorf("could not create maildir worker: %v", err)
- } else {
- worker.Backend = w
- }
- default:
- return nil, fmt.Errorf("Unknown backend %s", u.Scheme)
+ backend, err := handlers.GetHandlerForScheme(scheme, worker)
+ if err != nil {
+ return nil, err
}
+ worker.Backend = backend
return worker, nil
}