完善客户端连接流程处理和日志输出
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user