-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
55 lines (47 loc) · 1.25 KB
/
service.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
package backend
import (
"flag"
"github.com/aukbit/pluto"
"github.com/aukbit/pluto/examples/user/backend/views"
pb "github.com/aukbit/pluto/examples/user/proto"
"github.com/aukbit/pluto/server"
"github.com/aukbit/pluto/server/ext"
"github.com/gocql/gocql"
"google.golang.org/grpc"
)
var (
dbAddr string
grpcPort string
)
func init() {
flag.StringVar(&dbAddr, "db_addr", "127.0.0.1", "cassandra address")
flag.StringVar(&grpcPort, "grpc_port", ":65087", "grpc listening port")
flag.Parse()
}
func Run() error {
// db connection
cfg := gocql.NewCluster(dbAddr)
cfg.Keyspace = "examples_user_backend"
cfg.ProtoVersion = 3
// Define Pluto Server
srv := server.New(
server.Addr(grpcPort),
server.GRPCRegister(func(g *grpc.Server) {
pb.RegisterUserServiceServer(g, &backend.UserViews{})
}),
server.UnaryServerInterceptors(ext.CassandraUnaryServerInterceptor("cassandra", cfg)),
server.StreamServerInterceptors(ext.CassandraStreamServerInterceptor("cassandra", cfg)),
)
// Define Pluto Service
s := pluto.New(
pluto.Name("backend"),
pluto.Description("Backend service is responsible for persist data"),
pluto.Servers(srv),
pluto.HealthAddr(":9096"),
)
// Run service
if err := s.Run(); err != nil {
return err
}
return nil
}