errGroup := syncutil.GroupErr{} var wg sync.WaitGroup for _, item := range items { wg.Add(1) go func(item Item) { defer wg.Done() err := processItem(item) if err != nil { errGroup.Add(err) } }(item) } wg.Wait() if errGroup.Err() != nil { // Handle the errors }
errGroup := syncutil.GroupErr{} errGroup.Add(errors.New("Something went wrong")) errGroup.Add(errors.New("Another thing went wrong")) fmt.Println("Errors:") for _, err := range errGroup.Errors() { fmt.Println(err.Error()) }In this example, we create an error group and add two errors to it using the Add method. The Errors method is then called to retrieve the individual errors contained in the group. Based on the package naming convention, camlistore.org/pkg/syncutil appears to be a library that provides utility functions for synchronization-related tasks in the Camlistore project.