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:
@@ -166,7 +166,7 @@ func (r *postRepository) UpdateWithImages(post *model.Post, images *[]string) er
|
||||
// UpdateModerationStatus 更新帖子审核状态
|
||||
func (r *postRepository) UpdateModerationStatus(postID string, status model.PostStatus, rejectReason string, reviewedBy string) error {
|
||||
// 审核状态更新属于管理操作,不应影响帖子内容更新时间(updated_at)
|
||||
updates := map[string]interface{}{
|
||||
updates := map[string]any{
|
||||
"status": status,
|
||||
"reviewed_at": gorm.Expr("CURRENT_TIMESTAMP"),
|
||||
"reviewed_by": reviewedBy,
|
||||
@@ -455,7 +455,7 @@ func (r *postRepository) IsFavoritedBatch(postIDs []string, userID string) map[s
|
||||
// IncrementViews 增加帖子观看量
|
||||
func (r *postRepository) IncrementViews(postID string) error {
|
||||
return r.db.Model(&model.Post{}).Where("id = ?", postID).
|
||||
UpdateColumns(map[string]interface{}{
|
||||
UpdateColumns(map[string]any{
|
||||
"views_count": gorm.Expr("views_count + 1"),
|
||||
"updated_at": gorm.Expr("updated_at"),
|
||||
}).Error
|
||||
@@ -467,7 +467,7 @@ func (r *postRepository) IncrementShares(postID string) (int, error) {
|
||||
err := r.db.Transaction(func(tx *gorm.DB) error {
|
||||
res := tx.Model(&model.Post{}).
|
||||
Where("id = ? AND status = ?", postID, model.PostStatusPublished).
|
||||
Updates(map[string]interface{}{
|
||||
Updates(map[string]any{
|
||||
"shares_count": gorm.Expr("shares_count + 1"),
|
||||
"updated_at": gorm.Expr("updated_at"),
|
||||
})
|
||||
@@ -909,11 +909,11 @@ func (r *postRepository) BatchUpdateStatus(ids []string, status model.PostStatus
|
||||
result := r.db.Model(&model.Post{}).
|
||||
Where("id IN ?", ids).
|
||||
Updates(map[string]any{
|
||||
"status": status,
|
||||
"reviewed_at": gorm.Expr("CURRENT_TIMESTAMP"),
|
||||
"reviewed_by": reviewedBy,
|
||||
"status": status,
|
||||
"reviewed_at": gorm.Expr("CURRENT_TIMESTAMP"),
|
||||
"reviewed_by": reviewedBy,
|
||||
"reject_reason": "",
|
||||
"updated_at": gorm.Expr("updated_at"),
|
||||
"updated_at": gorm.Expr("updated_at"),
|
||||
})
|
||||
|
||||
if result.Error != nil {
|
||||
|
||||
Reference in New Issue
Block a user