-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathperso.go
46 lines (37 loc) · 973 Bytes
/
perso.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"log"
"net/http"
"time"
)
func main() {
conf := newConfig()
conf.parseFlags()
// Provides help text based on user configuration
help := newHelp(conf.keys)
// Keep track of what is searcheable
indexer := newMailIndexer(conf.keys)
// Handle all requests to the cache (searching or adding)
caches := newCaches(indexer, conf.root)
go caches.run()
// First crawl. HTTP listener won't start before
crawler := newCrawler(indexer, caches, conf.root)
crawler.scan()
if conf.interval > 0 {
go func() {
notify, err := newNotify(conf.root)
if err != nil {
log.Fatal("inotify setup error: ", err)
}
// Keep crawling for new or deleted messages
crawler.run(
notify.eventsChannel(),
notify.errorsChannel(),
time.Tick(time.Duration(conf.interval)),
)
}()
}
// Handle all HTTP requests here
handler := newHttpHandler(help, caches, conf, indexer)
log.Fatal(http.ListenAndServe(conf.listen, handler))
}