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

@@ -516,15 +516,15 @@ type PushRecordListResponse struct {
// SystemMessageResponse 系统消息响应
type SystemMessageResponse struct {
ID string `json:"id"`
SenderID string `json:"sender_id"`
ReceiverID string `json:"receiver_id"`
Content string `json:"content"`
Category string `json:"category"`
SystemType string `json:"system_type"`
ExtraData map[string]interface{} `json:"extra_data,omitempty"`
IsRead bool `json:"is_read"`
CreatedAt time.Time `json:"created_at"`
ID string `json:"id"`
SenderID string `json:"sender_id"`
ReceiverID string `json:"receiver_id"`
Content string `json:"content"`
Category string `json:"category"`
SystemType string `json:"system_type"`
ExtraData map[string]any `json:"extra_data,omitempty"`
IsRead bool `json:"is_read"`
CreatedAt time.Time `json:"created_at"`
}
// SystemMessageListResponse 系统消息列表响应
@@ -905,10 +905,10 @@ type VoteResultDTO struct {
// WSResponse WebSocket响应结构体
type WSResponse struct {
Success bool `json:"success"` // 是否成功
Action string `json:"action"` // 响应原action
Data interface{} `json:"data,omitempty"` // 响应数据
Error string `json:"error,omitempty"` // 错误信息
Success bool `json:"success"` // 是否成功
Action string `json:"action"` // 响应原action
Data any `json:"data,omitempty"` // 响应数据
Error string `json:"error,omitempty"` // 错误信息
}
// ==================== Admin Post DTOs ====================
@@ -1212,13 +1212,13 @@ type CursorPageRequest struct {
}
// CursorPageResponse 游标分页响应(泛型版本)
// 注意:由于 Go 的限制,这里使用 interface{} 作为 Items 类型
// 注意:由于 Go 的限制,这里使用 any 作为 Items 类型
// 实际使用时可以创建特定类型的响应结构体
type CursorPageResponse struct {
Items interface{} `json:"list"`
NextCursor string `json:"next_cursor,omitempty"` // 下一页游标
PrevCursor string `json:"prev_cursor,omitempty"` // 上一页游标(可选)
HasMore bool `json:"has_more"` // 是否有更多数据
Items any `json:"list"`
NextCursor string `json:"next_cursor,omitempty"` // 下一页游标
PrevCursor string `json:"prev_cursor,omitempty"` // 上一页游标(可选)
HasMore bool `json:"has_more"` // 是否有更多数据
}
// CursorPageMeta 分页元信息

View File

@@ -54,7 +54,7 @@ func SystemMessageToResponse(msg *model.Message) *SystemMessageResponse {
CreatedAt: msg.CreatedAt,
}
if msg.ExtraData != nil {
resp.ExtraData = map[string]interface{}{
resp.ExtraData = map[string]any{
"actor_id": msg.ExtraData.ActorID,
"actor_name": msg.ExtraData.ActorName,
"avatar_url": msg.ExtraData.AvatarURL,
@@ -92,7 +92,7 @@ func SystemNotificationToResponse(n *model.SystemNotification) *SystemMessageRes
CreatedAt: n.CreatedAt,
}
if n.ExtraData != nil {
resp.ExtraData = map[string]interface{}{
resp.ExtraData = map[string]any{
"actor_id": n.ExtraData.ActorID,
"actor_id_str": n.ExtraData.ActorIDStr,
"actor_name": n.ExtraData.ActorName,

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,