优化节点连接管理逻辑与日志输出,修改连接错误处理函数的返回值以确保错误处理灵活性

This commit is contained in:
2025-05-29 14:44:06 +08:00
parent 1831c792ad
commit ceb381bc9b
9 changed files with 57 additions and 48 deletions

View File

@@ -1,8 +1,10 @@
package utils
import (
"fmt"
"io"
"log/slog"
"runtime"
)
func ReadByte(reader io.Reader) (byte, error) {
@@ -32,7 +34,12 @@ func Close(v any) {
if v, ok := v.(io.Closer); ok {
err := v.Close()
if err != nil {
slog.Warn("对象关闭失败", "err", err)
var logger = slog.Default()
_, file, line, ok := runtime.Caller(1)
if ok {
logger = logger.With("source", fmt.Sprintf("%s:%d", file, line))
}
logger.Warn("对象关闭失败", "err", err)
}
}
}