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:
@@ -2,24 +2,29 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// 初始化应用程序(Wire 自动生成)
|
||||
app, err := InitializeApp()
|
||||
if err != nil {
|
||||
log.Fatalf("failed to initialize app: %v", err)
|
||||
zap.L().Fatal("failed to initialize app",
|
||||
zap.Error(err),
|
||||
)
|
||||
}
|
||||
|
||||
// 启动应用程序
|
||||
ctx := context.Background()
|
||||
if err := app.Start(ctx); err != nil {
|
||||
log.Fatalf("failed to start app: %v", err)
|
||||
app.Logger.Fatal("failed to start app",
|
||||
zap.Error(err),
|
||||
)
|
||||
}
|
||||
|
||||
// 优雅关闭
|
||||
@@ -31,6 +36,8 @@ func main() {
|
||||
defer cancel()
|
||||
|
||||
if err := app.Stop(shutdownCtx); err != nil {
|
||||
log.Printf("Error during shutdown: %v", err)
|
||||
app.Logger.Error("Error during shutdown",
|
||||
zap.Error(err),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user