完善客户端连接流程处理和日志输出

This commit is contained in:
2025-02-25 00:46:16 +08:00
parent 83f4f06740
commit c24a1e1621
6 changed files with 211 additions and 129 deletions

View File

@@ -1,6 +1,9 @@
package utils
import "io"
import (
"io"
"log/slog"
)
func ReadByte(reader io.Reader) (byte, error) {
buffer, err := ReadBuffer(reader, 1)
@@ -20,3 +23,16 @@ func ReadBuffer(reader io.Reader, size int) ([]byte, error) {
return buffer, nil
}
func Close[T any](v *T) {
if v == nil {
return
}
closer, ok := any(*v).(io.Closer)
if ok {
err := closer.Close()
if err != nil {
slog.Warn("对象关闭失败", "err", err)
}
}
}