- Add package documentation for internal, etag, and bytes files - Include author attribution (xfy)
26 lines
611 B
Go
26 lines
611 B
Go
// Package utils 提供通用的工具函数和辅助类型。
|
||
//
|
||
// 包含 ETag 生成相关的工具函数,用于处理缓存验证。
|
||
//
|
||
// 作者:xfy
|
||
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)
|
||
}
|