-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (30 loc) · 872 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
package main
import (
"flag"
"log"
"github.com/VivaLaPanda/isle-api/api/models"
"github.com/VivaLaPanda/isle-api/api/router"
"github.com/dgraph-io/dgo"
"github.com/dgraph-io/dgo/protos/api"
"google.golang.org/grpc"
)
// Various runtime flags
var dbAddress = flag.String("dbAddress", "127.0.0.1:9080", "HTTP address of the dgraph database")
var serverPort = flag.Int("serverPort", 9090, "Port to run the REST api on")
func main() {
flag.Parse()
dbClient := newClient(*dbAddress)
models.LoadSchema(dbClient)
router.ServeAPI(*serverPort, dbClient)
}
func newClient(dbAddress string) *dgo.Dgraph {
// Dial a gRPC connection. The address to dial to can be configured when
// setting up the dgraph cluster.
d, err := grpc.Dial(dbAddress, grpc.WithInsecure())
if err != nil {
log.Fatal(err)
}
return dgo.NewDgraphClient(
api.NewDgraphClient(d),
)
}