package tools import "unicode/utf8" // CutUTF8 按字节上限截断,并回退到完整 rune,避免切开 UTF-8。 func CutUTF8(s string, maxBytes int) string { if maxBytes <= 0 || len(s) <= maxBytes { return s } end := maxBytes for end > 0 && !utf8.ValidString(s[:end]) { end-- } return s[:end] }