-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmain.go
57 lines (54 loc) · 1.92 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
56
57
package main
import (
"fmt"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
_ "github.com/grpc-ecosystem/go-grpc-middleware/auth"
grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
grpc_ctxtags "github.com/grpc-ecosystem/go-grpc-middleware/tags"
grpc_opentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
"gome/api"
"gome/engine"
rpc "gome/grpc"
"gome/request"
"gome/utils"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
"log"
)
func main() {
defer func() {
if err := recover(); err != nil {
fmt.Println(err)
}
}()
rpcListener := rpc.NewRpcListener()
listener := rpcListener.Listener
rpcServer := grpc.NewServer(
grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(
grpc_ctxtags.StreamServerInterceptor(),
grpc_opentracing.StreamServerInterceptor(),
//grpc_prometheus.StreamServerInterceptor,
//grpc_zap.StreamServerInterceptor(ZapInterceptor()),
grpc_zap.StreamServerInterceptor(utils.ZapFileInterceptor()),
//grpc_auth.StreamServerInterceptor(myAuthFunction),
grpc_recovery.StreamServerInterceptor(utils.RecoveryInterceptor()),
)),
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
grpc_ctxtags.UnaryServerInterceptor(),
grpc_opentracing.UnaryServerInterceptor(),
//grpc_prometheus.UnaryServerInterceptor,
//grpc_zap.UnaryServerInterceptor(utils.ZapFileInterceptor(), request.GetOption()),
request.UnaryServerInterceptor(utils.ZapFileInterceptor()),
//grpc_auth.UnaryServerInterceptor(myAuthFunction),
grpc_recovery.UnaryServerInterceptor(utils.RecoveryInterceptor()),
)),
)
api.RegisterOrderServer(rpcServer, &engine.Order{})
api.RegisterPoolServer(rpcServer, &engine.Pool{})
reflection.Register(rpcServer)
if err := rpcServer.Serve(listener); err != nil {
log.Println("错误:", err)
log.Fatalln("服务启动失败")
}
}