Extract duplicate generateETag function from handler/static.go and cache/file_cache.go into internal/utils/etag.go. Both functions were identical, using strconv.AppendInt for zero-allocation ETag generation. - Create utils.GenerateETag(modTime, size) as the unified implementation - Update handler/static.go to call utils.GenerateETag - Update cache/file_cache.go to call utils.GenerateETag - Remove unused strconv import from static.go Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
21 lines
453 B
Go
21 lines
453 B
Go
package utils
|
|
|
|
import (
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
// GenerateETag 基于 ModTime 和 Size 生成 ETag。
|
|
// 使用 strconv.AppendInt 避免 fmt.Sprintf 分配。
|
|
// 格式: "<modtime-unix-hex>-<size-hex>"
|
|
func GenerateETag(modTime time.Time, size int64) string {
|
|
var buf [32]byte
|
|
b := buf[:0]
|
|
b = append(b, '"')
|
|
b = strconv.AppendInt(b, modTime.Unix(), 16)
|
|
b = append(b, '-')
|
|
b = strconv.AppendInt(b, size, 16)
|
|
b = append(b, '"')
|
|
return string(b)
|
|
}
|