refactor: upgrade to Go 1.26 and modernize code idioms
- 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:
@@ -91,7 +91,7 @@ func (r *messageRepository) CreateConversationWithParticipants(conv *model.Conve
|
||||
participant := model.ConversationParticipant{
|
||||
ConversationID: conv.ID,
|
||||
UserID: userID,
|
||||
LastReadSeq: 0,
|
||||
LastReadSeq: 0,
|
||||
}
|
||||
if err := tx.Create(&participant).Error; err != nil {
|
||||
return err
|
||||
@@ -291,7 +291,7 @@ func (r *messageRepository) UpdateLastReadSeq(conversationID string, userID stri
|
||||
{Name: "conversation_id"},
|
||||
{Name: "user_id"},
|
||||
},
|
||||
DoUpdates: clause.Assignments(map[string]interface{}{
|
||||
DoUpdates: clause.Assignments(map[string]any{
|
||||
"last_read_seq": lastReadSeq,
|
||||
"updated_at": gorm.Expr("CURRENT_TIMESTAMP"),
|
||||
}),
|
||||
@@ -324,7 +324,7 @@ func (r *messageRepository) UpdatePinned(conversationID string, userID string, i
|
||||
{Name: "conversation_id"},
|
||||
{Name: "user_id"},
|
||||
},
|
||||
DoUpdates: clause.Assignments(map[string]interface{}{
|
||||
DoUpdates: clause.Assignments(map[string]any{
|
||||
"is_pinned": isPinned,
|
||||
"updated_at": gorm.Expr("CURRENT_TIMESTAMP"),
|
||||
}),
|
||||
@@ -358,7 +358,7 @@ func (r *messageRepository) GetUnreadCount(conversationID string, userID string)
|
||||
func (r *messageRepository) UpdateConversationLastSeq(conversationID string, seq int64) error {
|
||||
return r.db.Model(&model.Conversation{}).
|
||||
Where("id = ?", conversationID).
|
||||
Updates(map[string]interface{}{
|
||||
Updates(map[string]any{
|
||||
"last_seq": seq,
|
||||
"last_msg_time": gorm.Expr("CURRENT_TIMESTAMP"),
|
||||
}).Error
|
||||
@@ -393,7 +393,7 @@ func (r *messageRepository) CreateMessageWithSeq(msg *model.Message) error {
|
||||
// 更新会话的last_seq
|
||||
if err := tx.Model(&model.Conversation{}).
|
||||
Where("id = ?", msg.ConversationID).
|
||||
Updates(map[string]interface{}{
|
||||
Updates(map[string]any{
|
||||
"last_seq": msg.Seq,
|
||||
"last_msg_time": gorm.Expr("CURRENT_TIMESTAMP"),
|
||||
}).Error; err != nil {
|
||||
@@ -455,7 +455,7 @@ func (r *messageRepository) UpdateMessageStatus(messageID string, status model.M
|
||||
func (r *messageRepository) RecallMessage(messageID string, userID string) error {
|
||||
return r.db.Model(&model.Message{}).
|
||||
Where("id = ? AND sender_id = ?", messageID, userID).
|
||||
Updates(map[string]interface{}{
|
||||
Updates(map[string]any{
|
||||
"status": model.MessageStatusRecalled,
|
||||
"segments": model.MessageSegments{},
|
||||
}).Error
|
||||
@@ -526,7 +526,7 @@ func (r *messageRepository) MarkAllSystemMessagesAsRead(userID string) error {
|
||||
{Name: "conversation_id"},
|
||||
{Name: "user_id"},
|
||||
},
|
||||
DoUpdates: clause.Assignments(map[string]interface{}{
|
||||
DoUpdates: clause.Assignments(map[string]any{
|
||||
"last_read_seq": maxSeq,
|
||||
"updated_at": gorm.Expr("CURRENT_TIMESTAMP"),
|
||||
}),
|
||||
@@ -653,7 +653,7 @@ func (r *messageRepository) BatchUpdateParticipants(ctx context.Context, updates
|
||||
|
||||
var cases []string
|
||||
var whereClauses []string
|
||||
var args []interface{}
|
||||
var args []any
|
||||
|
||||
for _, u := range updates {
|
||||
cases = append(cases, "WHEN (conversation_id = ? AND user_id = ?) THEN ?")
|
||||
@@ -678,7 +678,7 @@ func (r *messageRepository) UpdateConversationLastSeqWithContext(ctx context.Con
|
||||
return r.db.WithContext(ctx).
|
||||
Model(&model.Conversation{}).
|
||||
Where("id = ?", convID).
|
||||
Updates(map[string]interface{}{
|
||||
Updates(map[string]any{
|
||||
"last_seq": lastSeq,
|
||||
"last_msg_time": lastMsgTime,
|
||||
"updated_at": time.Now(),
|
||||
@@ -701,7 +701,7 @@ func (r *messageRepository) BatchUpdateParticipantsWithTx(tx *gorm.DB, updates [
|
||||
|
||||
var cases []string
|
||||
var whereClauses []string
|
||||
var args []interface{}
|
||||
var args []any
|
||||
|
||||
for _, u := range updates {
|
||||
cases = append(cases, "WHEN (conversation_id = ? AND user_id = ?) THEN ?")
|
||||
@@ -725,7 +725,7 @@ func (r *messageRepository) BatchUpdateParticipantsWithTx(tx *gorm.DB, updates [
|
||||
func (r *messageRepository) UpdateConversationLastSeqWithTx(tx *gorm.DB, convID string, lastSeq int64, lastMsgTime time.Time) error {
|
||||
return tx.Model(&model.Conversation{}).
|
||||
Where("id = ?", convID).
|
||||
Updates(map[string]interface{}{
|
||||
Updates(map[string]any{
|
||||
"last_seq": lastSeq,
|
||||
"last_msg_time": lastMsgTime,
|
||||
"updated_at": time.Now(),
|
||||
|
||||
Reference in New Issue
Block a user