diff --git a/cmd/restic/cmd_check.go b/cmd/restic/cmd_check.go index a88649f20..cdfcb8cbc 100644 --- a/cmd/restic/cmd_check.go +++ b/cmd/restic/cmd_check.go @@ -342,13 +342,11 @@ func runCheck(ctx context.Context, opts CheckOptions, gopts global.Options, args var brokenSnapshots []string var wg sync.WaitGroup - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { bar := printer.NewCounter("snapshots") defer bar.Done() chkr.Structure(ctx, bar, errChan) - }() + }) for err := range errChan { errorsFound = true diff --git a/internal/backend/rclone/backend.go b/internal/backend/rclone/backend.go index a5944062d..7038f2660 100644 --- a/internal/backend/rclone/backend.go +++ b/internal/backend/rclone/backend.go @@ -56,16 +56,14 @@ func run(errorLog func(string, ...any), command string, args ...string) (*StdioC waitCh := make(chan struct{}) // start goroutine to add a prefix to all messages printed by to stderr by rclone - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { defer close(waitCh) sc := bufio.NewScanner(p) for sc.Scan() { errorLog("rclone: %v\n", sc.Text()) } debug.Log("command has exited, closing waitCh") - }() + }) r, stdin, err := os.Pipe() if err != nil { @@ -207,9 +205,7 @@ func newBackend(ctx context.Context, cfg Config, lim limiter.Limiter, errorLog f ctx, cancel := context.WithCancel(ctx) defer cancel() - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { <-waitCh cancel() @@ -219,7 +215,7 @@ func newBackend(ctx context.Context, cfg Config, lim limiter.Limiter, errorLog f be.waitResult = err // close our side of the pipes to rclone, ignore errors _ = stdioConn.CloseAll() - }() + }) // send an HTTP request to the base URL, see if the server is there client := http.Client{ diff --git a/internal/backend/sema/backend_test.go b/internal/backend/sema/backend_test.go index 582a3114b..cfa42acb0 100644 --- a/internal/backend/sema/backend_test.go +++ b/internal/backend/sema/backend_test.go @@ -225,12 +225,10 @@ func TestFreeze(t *testing.T) { // Start Save call that should block var wg sync.WaitGroup - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { h := backend.Handle{Type: backend.PackFile, Name: "foobar"} test.OK(t, be.Save(context.TODO(), h, nil)) - }() + }) // check time.Sleep(1 * time.Millisecond) diff --git a/internal/ui/termstatus/status.go b/internal/ui/termstatus/status.go index 892e4c712..b0b831c7f 100644 --- a/internal/ui/termstatus/status.go +++ b/internal/ui/termstatus/status.go @@ -80,11 +80,9 @@ func Setup(stdin io.ReadCloser, stdout, stderr io.Writer, quiet bool) (ui.Termin cancelCtx, cancel := context.WithCancel(context.Background()) term := new(stdin, stdout, stderr, quiet) - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { term.Run(cancelCtx) - }() + }) return term, func() { if term.outputWriter != nil {