feat 自定义拦截器
This commit is contained in:
@@ -19,13 +19,14 @@ type IService interface {
|
||||
}
|
||||
|
||||
type Base struct {
|
||||
Target string
|
||||
ServiceName string
|
||||
SID string
|
||||
Serve *grpc.Server
|
||||
EtcdTTL int64
|
||||
OnInit func(serve *grpc.Server)
|
||||
OnClose func()
|
||||
Target string
|
||||
ServiceName string
|
||||
SID string
|
||||
Serve *grpc.Server
|
||||
EtcdTTL int64
|
||||
OnCustomGrpcServerOption func() []grpc.ServerOption
|
||||
OnInit func(serve *grpc.Server)
|
||||
OnClose func()
|
||||
|
||||
wg *sync.WaitGroup
|
||||
}
|
||||
@@ -46,7 +47,7 @@ func (s *Base) Init(addr string, port int32) {
|
||||
return
|
||||
}
|
||||
|
||||
s.Serve = grpc.NewServer(
|
||||
options := []grpc.ServerOption{
|
||||
grpc.ChainUnaryInterceptor(
|
||||
s.RecoveryInterceptor,
|
||||
s.LoggingInterceptor,
|
||||
@@ -56,7 +57,9 @@ func (s *Base) Init(addr string, port int32) {
|
||||
MinTime: 20 * time.Second,
|
||||
PermitWithoutStream: true,
|
||||
}),
|
||||
)
|
||||
}
|
||||
options = append(options, s.OnCustomGrpcServerOption()...)
|
||||
s.Serve = grpc.NewServer(options...)
|
||||
s.OnInit(s.Serve)
|
||||
|
||||
// 服务注册
|
||||
|
||||
Reference in New Issue
Block a user