xfy911 4a53d3032a docs(utils): add package comments for utils module
- Add package documentation for internal, etag, and bytes files
- Include author attribution (xfy)
2026-06-03 15:28:53 +08:00

26 lines
611 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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)
}