-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.go
46 lines (36 loc) · 860 Bytes
/
server.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
package main
import (
"ksuser/config"
"ksuser/lib/database/postgres"
"ksuser/route"
"log"
"net"
"os"
_ "github.com/lib/pq"
"google.golang.org/grpc"
)
func main() {
config.Setup(".env")
log := log.New(os.Stdout, "grpc ksuser : ", log.LstdFlags|log.Lmicroseconds|log.Lshortfile)
db, err := postgres.Open()
if err != nil {
log.Fatalf("connecting to db: %v", err)
return
}
log.Print("connecting to postgresql database")
defer db.Close()
// listen tcp port
lis, err := net.Listen("tcp", ":"+os.Getenv("PORT"))
if err != nil {
log.Fatalf("failed to listen: %v", err)
return
}
grpcServer := grpc.NewServer()
// routing grpc services
route.GrpcRoute(grpcServer, log, db)
if err := grpcServer.Serve(lis); err != nil {
log.Fatalf("failed to serve: %s", err)
return
}
log.Print("serve grpc on port: " + os.Getenv("PORT"))
}