refactor: replace standard log with zap logger and optimize code patterns

- Migrate all log.Printf/log.Println calls to structured zap logging
- Use cmp.Or for cleaner default value handling
- Replace manual loops with slices.ContainsFunc/IndexFunc
- Add batch query methods (IsLikedBatch, IsFavoritedBatch) to solve N+1 problem
- Update JSON tags from omitempty to omitzero for numeric fields
- Use errgroup-style wg.Go for worker goroutines
- Remove duplicate casbin/v2 dependency (keeping v3)
- Add plans/ to gitignore
This commit is contained in:
lafay
2026-03-17 00:47:17 +08:00
parent b028f7e1d3
commit 5d6c982c9c
38 changed files with 2256 additions and 290 deletions

View File

@@ -1,10 +1,10 @@
package handler
import (
"log"
"strconv"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
"carrot_bbs/internal/dto"
"carrot_bbs/internal/model"
@@ -1361,12 +1361,24 @@ func (h *GroupHandler) HandleSetGroupBan(c *gin.Context) {
// duration > 0 或 duration = -1 表示禁言duration = 0 表示解除禁言
muted := params.Duration != 0
log.Printf("[HandleSetGroupBan] 开始禁言操作: userID=%s, groupID=%s, targetUserID=%s, duration=%d, muted=%v", userID, groupID, params.UserID, params.Duration, muted)
zap.L().Info("开始禁言操作",
zap.String("component", "HandleSetGroupBan"),
zap.String("userID", userID),
zap.String("groupID", groupID),
zap.String("targetUserID", params.UserID),
zap.Int64("duration", params.Duration),
zap.Bool("muted", muted),
)
err := h.groupService.MuteMember(userID, groupID, params.UserID, muted)
if err != nil {
log.Printf("[HandleSetGroupBan] 禁言操作失败: %v", err)
zap.L().Warn("禁言操作失败",
zap.String("component", "HandleSetGroupBan"),
zap.Error(err),
)
} else {
log.Printf("[HandleSetGroupBan] 禁言操作成功")
zap.L().Info("禁言操作成功",
zap.String("component", "HandleSetGroupBan"),
)
}
if err != nil {
if err == service.ErrNotGroupAdmin {