// Package utils 提供通用的工具函数和辅助类型。 // // 包含 ETag 生成相关的工具函数,用于处理缓存验证。 // // 作者:xfy package utils import ( "strconv" "time" ) // GenerateETag 基于 ModTime 和 Size 生成 ETag。 // 使用 strconv.AppendInt 避免 fmt.Sprintf 分配。 // 格式: "-" 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) }