-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (42 loc) · 1.06 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
package main
import (
"fmt"
"net"
"github.com/fiuskylab/grpc-example/common"
"github.com/fiuskylab/grpc-example/proto"
"github.com/fiuskylab/grpc-example/services/auth/entity"
"github.com/fiuskylab/grpc-example/services/auth/repository"
"github.com/fiuskylab/grpc-example/services/auth/server"
"github.com/fiuskylab/grpc-example/storage"
"google.golang.org/grpc"
)
func main() {
c := common.NewCommon()
lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%s", c.Env.AUTH_PORT))
if err != nil {
c.Log.Error(err.Error())
return
}
var opts []grpc.ServerOption
grpcServer := grpc.NewServer(opts...)
sto, err := storage.NewStorage(c)
if err != nil {
c.Log.Error(err.Error())
return
}
if err = sto.PGSQL.AutoMigrate(entity.User{}); err != nil {
c.Log.Error(err.Error())
return
}
r := repository.NewAuthRepo(c, sto)
sv, err := server.NewServer(c, r)
if err != nil {
c.Log.Error(err.Error())
return
}
proto.RegisterAuthServiceServer(grpcServer, sv)
if err = grpcServer.Serve(lis); err != nil {
c.Log.Error(err.Error())
return
}
}