From 9fce7acead1f6fe64be2580d347e6955fc360c56 Mon Sep 17 00:00:00 2001 From: wangwenbin Date: Thu, 28 Dec 2023 17:46:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96ErrGroup=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E5=88=87=E7=89=87=E7=9A=84=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- err_group/weather.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/err_group/weather.go b/err_group/weather.go index 1ebe5d2..6793db1 100644 --- a/err_group/weather.go +++ b/err_group/weather.go @@ -47,13 +47,13 @@ func GetAllCityWeatherData(timeOut time.Duration) ([]*WeatherData, error) { // 创建一个携带cancel的context ctx, cancel := context.WithTimeout(context.Background(), timeOut) defer cancel() // 确保所有路径都调用cancel - list := make([]*WeatherData, 0) // 初始化一个ErrGroup对象 g, ctx := errgroup.WithContext(ctx) // 城市列表 cities := []string{"New York", "Tokyo", "Berlin", "Paris", "Beijing"} + list := make([]*WeatherData, 0, len(cities)) // 循环启动goroutine来获取每个城市的天气数据 for _, city := range cities {