feat 自定义拦截器

This commit is contained in:
2026-01-16 23:50:14 +08:00
parent d944729ad0
commit 3de703eb83

View File

@@ -24,6 +24,7 @@ type Base struct {
SID string
Serve *grpc.Server
EtcdTTL int64
OnCustomGrpcServerOption func() []grpc.ServerOption
OnInit func(serve *grpc.Server)
OnClose func()
@@ -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)
// 服务注册