refactor(handler): 提取平台字符串为常量
- 使用 platformLinux 常量替代硬编码字符串 "linux" Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a10377f76d
commit
a965040eff
@ -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
|
||||
|
||||
@ -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")
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user