refactor: upgrade to Go 1.26 and modernize code idioms
All checks were successful
Build Backend / build (push) Successful in 3m51s
Build Backend / build-docker (push) Successful in 1m0s

- Replace `interface{}` with `any` type alias across all packages
- Use built-in `min()`/`max()` for parameter clamping
- Use `slices.SortFunc`, `slices.Min`, `slices.Max` for cleaner code
- Use `strings.Cut()` for simpler string parsing in auth middleware
- Use `errors.Is()` for proper error comparison in handlers
- Update dependencies: golang.org/x/image 0.37.0 -> 0.38.0
- Add Wire code generation guidelines to ARCHITECTURE.md
- Disable Go cache in CI build workflow
This commit is contained in:
lafay
2026-03-30 04:49:35 +08:00
parent a69b2026f4
commit b640c9a249
47 changed files with 368 additions and 352 deletions

View File

@@ -9,7 +9,7 @@ import (
)
// ParseSegmentData 解析Segment数据到目标结构体
func ParseSegmentData(segment model.MessageSegment, target interface{}) error {
func ParseSegmentData(segment model.MessageSegment, target any) error {
dataBytes, err := json.Marshal(segment.Data)
if err != nil {
return err
@@ -21,7 +21,7 @@ func ParseSegmentData(segment model.MessageSegment, target interface{}) error {
func NewTextSegment(content string) model.MessageSegment {
return model.MessageSegment{
Type: string(SegmentTypeText),
Data: map[string]interface{}{"text": content},
Data: map[string]any{"text": content},
}
}
@@ -29,7 +29,7 @@ func NewTextSegment(content string) model.MessageSegment {
func NewImageSegment(url string, width, height int, thumbnailURL string) model.MessageSegment {
return model.MessageSegment{
Type: string(SegmentTypeImage),
Data: map[string]interface{}{
Data: map[string]any{
"url": url,
"width": width,
"height": height,
@@ -42,7 +42,7 @@ func NewImageSegment(url string, width, height int, thumbnailURL string) model.M
func NewImageSegmentWithSize(url string, width, height int, thumbnailURL string, fileSize int64) model.MessageSegment {
return model.MessageSegment{
Type: string(SegmentTypeImage),
Data: map[string]interface{}{
Data: map[string]any{
"url": url,
"width": width,
"height": height,
@@ -56,7 +56,7 @@ func NewImageSegmentWithSize(url string, width, height int, thumbnailURL string,
func NewVoiceSegment(url string, duration int, fileSize int64) model.MessageSegment {
return model.MessageSegment{
Type: string(SegmentTypeVoice),
Data: map[string]interface{}{
Data: map[string]any{
"url": url,
"duration": duration,
"file_size": fileSize,
@@ -68,7 +68,7 @@ func NewVoiceSegment(url string, duration int, fileSize int64) model.MessageSegm
func NewVideoSegment(url string, width, height, duration int, thumbnailURL string, fileSize int64) model.MessageSegment {
return model.MessageSegment{
Type: string(SegmentTypeVideo),
Data: map[string]interface{}{
Data: map[string]any{
"url": url,
"width": width,
"height": height,
@@ -83,7 +83,7 @@ func NewVideoSegment(url string, width, height, duration int, thumbnailURL strin
func NewFileSegment(url, name string, size int64, mimeType string) model.MessageSegment {
return model.MessageSegment{
Type: string(SegmentTypeFile),
Data: map[string]interface{}{
Data: map[string]any{
"url": url,
"name": name,
"size": size,
@@ -96,7 +96,7 @@ func NewFileSegment(url, name string, size int64, mimeType string) model.Message
func NewAtSegment(userID string) model.MessageSegment {
return model.MessageSegment{
Type: string(SegmentTypeAt),
Data: map[string]interface{}{
Data: map[string]any{
"user_id": userID,
},
}
@@ -106,7 +106,7 @@ func NewAtSegment(userID string) model.MessageSegment {
func NewAtAllSegment() model.MessageSegment {
return model.MessageSegment{
Type: string(SegmentTypeAt),
Data: map[string]interface{}{
Data: map[string]any{
"user_id": "all",
},
}
@@ -116,7 +116,7 @@ func NewAtAllSegment() model.MessageSegment {
func NewReplySegment(messageID string) model.MessageSegment {
return model.MessageSegment{
Type: string(SegmentTypeReply),
Data: map[string]interface{}{"id": messageID},
Data: map[string]any{"id": messageID},
}
}
@@ -124,7 +124,7 @@ func NewReplySegment(messageID string) model.MessageSegment {
func NewFaceSegment(id int, name, url string) model.MessageSegment {
return model.MessageSegment{
Type: string(SegmentTypeFace),
Data: map[string]interface{}{
Data: map[string]any{
"id": id,
"name": name,
"url": url,
@@ -136,7 +136,7 @@ func NewFaceSegment(id int, name, url string) model.MessageSegment {
func NewLinkSegment(url, title, description, image string) model.MessageSegment {
return model.MessageSegment{
Type: string(SegmentTypeLink),
Data: map[string]interface{}{
Data: map[string]any{
"url": url,
"title": title,
"description": description,