-
Notifications
You must be signed in to change notification settings - Fork 11
/
main.go
51 lines (40 loc) · 885 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
50
51
package main
import (
"log"
"net/http"
"github.com/dgraph-io/dgo/v210"
"github.com/dgraph-io/dgo/v210/protos/api"
"github.com/dolan-in/dgman/v2"
"google.golang.org/grpc"
)
func newDgraphClient() *dgo.Dgraph {
d, err := grpc.Dial("localhost:9080", grpc.WithInsecure())
if err != nil {
panic(err)
}
return dgo.NewDgraphClient(
api.NewDgraphClient(d),
)
}
func newApi(dgoClient *dgo.Dgraph) *userAPI {
return &userAPI{
store: &userStore{c: dgoClient},
}
}
func main() {
dg := newDgraphClient()
schema, err := dgman.CreateSchema(dg, &User{})
if err != nil {
log.Fatalln("create schema", err)
}
log.Println(schema)
api := newApi(dg)
router := http.NewServeMux()
router.HandleFunc("/register", api.Register)
router.HandleFunc("/auth", api.Login)
server := http.Server{
Addr: ":4000",
Handler: router,
}
log.Fatal(server.ListenAndServe())
}