go 开启goroutine并捕获错误

func CreateGreeter() error {
var mu sync.Mutex
eg, _ := errgroup.WithContext(context.Background())
var info []biz.Info
m := make(map[string]string)

userlist := []string{"User0001", "User0002", "User0003", "User0004", "User0005"}
for _, s := range userlist {
tempNum := s
go func() {}()
eg.Go(
func() error {
err := r.data.db.Table("111").Where("User=?", tempNum).Find(&info).Error
if err != nil {
fmt.Println("查询失败")
return err
}

news := m
for _, b := range info {
mu.Lock()
news[tempNum] = b.Function_ID
mu.Unlock()
}
return nil
},
)

}

if err := eg.Wait(); err != nil {
return err
}

return nil
}

上一篇:TSINGSEE青犀视频开发景区网站如何通过Go语言html生成PDF?


下一篇:GRPC 的验证器