-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
42 lines (34 loc) · 956 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
package main
import (
"fmt"
"log"
"net"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
"github.com/ybalexdp/sample-grpc_recovery/pb"
"github.com/ybalexdp/sample-grpc_recovery/service"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
)
func main() {
//var recoveryFunc grpc_recovery.RecoveryHandlerFunc
opts := []grpc_recovery.Option{
grpc_recovery.WithRecoveryHandler(recoveryFunc),
}
server := grpc.NewServer(
grpc_middleware.WithUnaryServerChain(
grpc_recovery.UnaryServerInterceptor(opts...),
),
)
listenPort, err := net.Listen("tcp", ":2007")
if err != nil {
log.Fatalln(err)
}
sampleService := &service.SampleService{}
pb.RegisterSampleServer(server, sampleService)
server.Serve(listenPort)
}
func recoveryFunc(p interface{}) error {
fmt.Printf("p: %+v\n", p)
return grpc.Errorf(codes.Internal, "Unexpected error")
}