-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (45 loc) · 1.33 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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package main
import (
"log"
"runtime"
"github.com/jinzhu/gorm"
"github.com/nats-io/go-nats"
"github.com/r3labs/natsdb"
_ "github.com/jinzhu/gorm/dialects/postgres"
)
var n *nats.Conn
var db *gorm.DB
var err error
var handler natsdb.Handler
func startHandler() {
handler = natsdb.Handler{
NotFoundErrorMessage: natsdb.NotFound.Encoded(),
UnexpectedErrorMessage: natsdb.Unexpected.Encoded(),
DeletedMessage: []byte(`{"status":"deleted"}`),
Nats: n,
NewModel: func() natsdb.Model {
return &Entity{}
},
}
if _, err = n.Subscribe("authorization.get", handler.Get); err != nil {
log.Println("Error subscribing authorization.get")
}
if _, err = n.Subscribe("authorization.del", handler.Del); err != nil {
log.Println("Error subscribing authorization.del")
}
if _, err = n.Subscribe("authorization.set", handler.Set); err != nil {
log.Println("Error subscribing authorization.set")
}
if _, err = n.Subscribe("authorization.find", handler.Find); err != nil {
log.Println("Error subscribing authorization.find")
}
}
func main() {
setupNats()
setupPg()
startHandler()
runtime.Goexit()
}