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