拆分 main 功能模块

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-06-17 11:29:51 +08:00
co-authored by Claude
parent 132ab2a1cb
commit ccc1260fe0
21 changed files with 2318 additions and 2074 deletions
+53
View File
@@ -0,0 +1,53 @@
package utils
import (
"crypto/rand"
"encoding/hex"
"encoding/json"
"fmt"
"strings"
)
func IntPtr(i int) *int { return &i }
func BoolPtr(v bool) *bool { return &v }
func TruncateString(text string, maxRunes int) string {
runes := []rune(strings.TrimSpace(text))
if maxRunes <= 0 || len(runes) <= maxRunes {
return string(runes)
}
return string(runes[:maxRunes]) + "..."
}
func Contains(items []string, target string) bool {
for _, item := range items {
if strings.TrimSpace(item) == target {
return true
}
}
return false
}
func NewUUID() string {
b := make([]byte, 16)
_, _ = rand.Read(b)
b[6] = (b[6] & 0x0f) | 0x40
b[8] = (b[8] & 0x3f) | 0x80
return hex.EncodeToString(b[:4]) + "-" + hex.EncodeToString(b[4:6]) + "-" +
hex.EncodeToString(b[6:8]) + "-" + hex.EncodeToString(b[8:10]) + "-" +
hex.EncodeToString(b[10:])
}
func ToJSON(s string) string {
b, _ := json.Marshal(s)
return string(b)
}
func ToSSE(s string) string {
s = strings.ReplaceAll(s, `\`, `\\`)
s = strings.ReplaceAll(s, "\n", `\n`)
s = strings.ReplaceAll(s, "\r", "")
s = strings.ReplaceAll(s, `"`, `\"`)
return fmt.Sprintf(`"%s"`, s)
}