-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
49 lines (39 loc) · 964 Bytes
/
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
package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"io/ioutil"
"os"
"github.com/wikidistance/wikidist/pkg/api"
"github.com/wikidistance/wikidist/pkg/db"
)
func main() {
// Get filename from args
filename := "../../config.json"
if len(os.Args) == 2 {
filename = os.Args[1]
}
// 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")
}
d, err := db.NewDGraph(config)
dg := (*api.DGraph)(d)
if err != nil {
log.Fatal("Couldn't connect to DGraph")
}
http.HandleFunc("/", api.DefaultHandler)
http.HandleFunc("/shortest", dg.ShortestPathHandler)
http.HandleFunc("/search", dg.PageSearchHandler)
http.HandleFunc("/search-uid", dg.UidSearchHandler)
fmt.Println("API is running on port 8081")
log.Fatal(http.ListenAndServe(":8081", nil))
}