diff --git a/internal/handler/sendfile.go b/internal/handler/sendfile.go index 037e33c..1447f2e 100644 --- a/internal/handler/sendfile.go +++ b/internal/handler/sendfile.go @@ -31,6 +31,9 @@ const ( // MinSendfileSize 使用 sendfile 的最小文件大小(8KB)。 // 小于该值的文件使用普通 io.Copy,避免系统调用开销。 MinSendfileSize = 8 * 1024 + + // platformLinux Linux 平台标识符。 + platformLinux = "linux" ) // SendFile 零拷贝文件传输。 @@ -135,7 +138,7 @@ func copyFile(ctx *fasthttp.RequestCtx, file *os.File, offset, length int64) err // - error: 传输错误或不支持时返回 ENOTSUP func platformSendfile(conn net.Conn, file *os.File, offset, length int64) error { switch runtime.GOOS { - case "linux": + case platformLinux: return linuxSendfile(conn, file.Fd(), offset, length) case "darwin": // macOS sendfile 签名复杂,简化使用 fallback diff --git a/internal/handler/sendfile_test.go b/internal/handler/sendfile_test.go index b87fe27..167a9c2 100644 --- a/internal/handler/sendfile_test.go +++ b/internal/handler/sendfile_test.go @@ -143,7 +143,7 @@ func TestCopyFile(t *testing.T) { // TestPlatformSendfile_NonLinux 测试非 Linux 平台的 sendfile 行为 func TestPlatformSendfile_NonLinux(t *testing.T) { - if runtime.GOOS == "linux" { + if runtime.GOOS == platformLinux { t.Skip("this test is for non-Linux platforms") } @@ -341,7 +341,7 @@ func TestCopyFile_Error(t *testing.T) { // TestLinuxSendfile_NilConn 测试 linuxSendfile 空连接 func TestLinuxSendfile_NilConn(t *testing.T) { - if runtime.GOOS != "linux" { + if runtime.GOOS != platformLinux { t.Skip("This test is for Linux only") }