-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
72 lines (55 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"strconv"
"syscall"
"github.com/wikidistance/wikidist/pkg/crawler"
"github.com/wikidistance/wikidist/pkg/db"
)
func main() {
args := os.Args[1:]
log.Println(args)
if len(args) != 3 && len(args) != 4 {
log.Println("Usage: crawler <prefix> <startTitle> <nWorkers> <config>")
return
}
nWorkers, err := strconv.Atoi(args[2])
if err != nil {
log.Println("nWorkers should be an integer")
return
}
// Get filename from args
filename := "../../config.json"
if len(args) == 4 {
filename = args[3]
}
// Get config from file
file, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatal("Couldn't open config file")
}
var config db.Config
err = json.Unmarshal(file, &config)
if err != nil {
log.Fatal("Couldn't parse config file")
}
client, err := db.NewDGraph(config)
if err != nil {
log.Fatal("Couldn't connect to DGraph")
}
c := crawler.NewCrawler(nWorkers, args[0], args[1], client)
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
c.Start()
done := make(chan os.Signal, 1)
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM)
<-done
log.Println("exiting")
}