diff --git a/example/concurrent/main.go b/example/concurrent/main.go index 1a91e4d..4dc6906 100644 --- a/example/concurrent/main.go +++ b/example/concurrent/main.go @@ -114,12 +114,12 @@ func main() { var totalQueries atomic.Int64 var queryErrors atomic.Int64 - for i := 0; i < queryCount; i++ { + for i := range queryCount { queryWg.Add(1) go func(queryID int) { defer queryWg.Done() - for j := 0; j < queriesPerGoroutine; j++ { + for j := range queriesPerGoroutine { // 随机选择一个 topic 进行查询 topic := topics[j%len(topics)] @@ -136,10 +136,7 @@ func main() { } // 查询最新的 10 条记录 - querySize := 10 - if count < querySize { - querySize = count - } + querySize := min(count, 10) _, err = processor.QueryNewest(count-1, querySize) if err != nil { @@ -180,7 +177,7 @@ func main() { go func(topicName string) { defer mixWg.Done() - for j := 0; j < 1000; j++ { + for j := range 1000 { data := fmt.Sprintf("mix-%s-msg-%d", topicName, j) if _, err := seq.Write(topicName, []byte(data)); err == nil { @@ -194,12 +191,12 @@ func main() { } // 启动查询 goroutine - for i := 0; i < 10; i++ { + for i := range 10 { mixWg.Add(1) go func(queryID int) { defer mixWg.Done() - for j := 0; j < 200; j++ { + for j := range 200 { topic := topics[j%len(topics)] processor, err := seq.GetProcessor(topic) @@ -267,7 +264,7 @@ func main() { } // 持续查询 goroutine - for i := 0; i < 5; i++ { + for i := range 5 { stressWg.Add(1) go func(queryID int) { defer stressWg.Done() @@ -296,8 +293,7 @@ func main() { } // 进度显示 goroutine - stressWg.Add(1) - go func() { + stressWg.Go(func() { defer stressWg.Done() ticker := time.NewTicker(10 * time.Second) defer ticker.Stop() @@ -314,7 +310,7 @@ func main() { stressQueryCount.Load()) } } - }() + }) stressWg.Wait() stressDuration := time.Since(stressTestStart) diff --git a/example/topic_processor/main.go b/example/topic_processor/main.go index 253faa1..6671ce1 100644 --- a/example/topic_processor/main.go +++ b/example/topic_processor/main.go @@ -10,7 +10,7 @@ import ( func main() { // ===== TopicProcessor 作为聚合器使用 ===== - fmt.Println("=== TopicProcessor 聚合器示例 ===\n") + fmt.Println("=== TopicProcessor 聚合器示例 ===") // 创建 TopicProcessor(提供空 handler) logger := slog.Default() diff --git a/example/webapp/main.go b/example/webapp/main.go index d9825ae..ffb9830 100644 --- a/example/webapp/main.go +++ b/example/webapp/main.go @@ -347,7 +347,7 @@ func handleIndex(w http.ResponseWriter, r *http.Request) {