-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
58 lines (50 loc) · 1.23 KB
/
main.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
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"os"
"os/signal"
"syscall"
"github.com/cyrildever/treee/api"
"github.com/cyrildever/treee/common/logger"
"github.com/cyrildever/treee/config"
"github.com/cyrildever/treee/core/index"
)
/** Usage:
*
* To launch the Treee indexing engine as a micro-service:
* `$ ./treee -t.port 7001 -t.host localhost -t.init 101`
*
* Stop it with Ctrl^c
*/
func main() {
log := logger.Init("main", "application")
conf, err := config.InitConfig(false)
if err != nil {
panic(err)
}
treee, err := index.Load(conf.IndexPath)
if err != nil {
log.Warn("Index doesn't exist, building one...", "error", err)
treee, err = index.New(conf.InitPrime)
if err != nil {
log.Crit("Unable to instantiate new index", "error", err)
return
}
log.Info("Index created", "initPrime", treee.InitPrime)
} else {
log.Info("Index up and running", "size", treee.Size(), "initPrime", treee.InitPrime)
}
index.Current = treee
willGracefullyStopIndex()
api.InitHTTPServer(conf)
}
// willGracefullyStopIndex ...
func willGracefullyStopIndex() {
log := logger.Init("main", "terminating")
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
log.Info("Goodbye ~")
os.Exit(1)
}()
}