mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
!138 fix: 后端数据连接断开后报空指针异常后程序中断问题
* fix(connection):fix the bug for nil error in connection when connection reset * fix(sqleditor): fix the spell error in sql editor
This commit is contained in:
@@ -2,6 +2,7 @@ package mgm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"mayfly-go/pkg/logx"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
@@ -28,5 +29,14 @@ func (mc *MongoConn) Close() error {
|
||||
}
|
||||
|
||||
func (mc *MongoConn) Ping() error {
|
||||
// 首先检查mc是否为nil
|
||||
if mc == nil {
|
||||
return fmt.Errorf("mc connection is nil")
|
||||
}
|
||||
|
||||
// 然后检查mc.Cli是否为nil,这是避免空指针异常的关键
|
||||
if mc.Cli == nil {
|
||||
return fmt.Errorf("mc client is nil")
|
||||
}
|
||||
return mc.Cli.Ping(context.Background(), nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user