refactor: use WaitGroup.Go to replace wg.Add(1)/go/wg.Done() boilerplate (#222)

https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/modernize#hdr-Analyzer_waitgroup
This commit is contained in:
Justin Bradford
2025-12-19 21:07:29 +10:00
committed by GitHub
parent 85a2615db1
commit 65e9cdd444
2 changed files with 8 additions and 23 deletions
+2 -5
View File
@@ -61,14 +61,11 @@ func (cli *Client) CreateIngressRecords(ctx context.Context, serviceID string) (
continue continue
} }
wg.Add(1) wg.Go(func() {
go func() {
defer wg.Done()
if err = verifyCaddyReachable(ctx, m.Machine); err == nil { if err = verifyCaddyReachable(ctx, m.Machine); err == nil {
reachableMachines <- m.Machine reachableMachines <- m.Machine
} }
}() })
} }
go func() { go func() {
+6 -18
View File
@@ -240,11 +240,7 @@ func (cli *Client) RemoveService(ctx context.Context, id string) error {
// Remove all containers on all machines that belong to the service. // Remove all containers on all machines that belong to the service.
for _, mc := range svc.Containers { for _, mc := range svc.Containers {
wg.Add(1) wg.Go(func() {
go func() {
defer wg.Done()
err := cli.StopContainer(ctx, svc.ID, mc.Container.ID, container.StopOptions{}) err := cli.StopContainer(ctx, svc.ID, mc.Container.ID, container.StopOptions{})
if err != nil { if err != nil {
errCh <- fmt.Errorf("stop container '%s': %w", mc.Container.ID, err) errCh <- fmt.Errorf("stop container '%s': %w", mc.Container.ID, err)
@@ -258,7 +254,7 @@ func (cli *Client) RemoveService(ctx context.Context, id string) error {
if err != nil && !errors.Is(err, api.ErrNotFound) { if err != nil && !errors.Is(err, api.ErrNotFound) {
errCh <- fmt.Errorf("remove container '%s': %w", mc.Container.ID, err) errCh <- fmt.Errorf("remove container '%s': %w", mc.Container.ID, err)
} }
}() })
} }
go func() { go func() {
@@ -286,16 +282,12 @@ func (cli *Client) StopService(ctx context.Context, id string, opts container.St
// Stop all containers on all machines that belong to the service. // Stop all containers on all machines that belong to the service.
for _, mc := range svc.Containers { for _, mc := range svc.Containers {
wg.Add(1) wg.Go(func() {
go func() {
defer wg.Done()
err := cli.StopContainer(ctx, svc.ID, mc.Container.ID, opts) err := cli.StopContainer(ctx, svc.ID, mc.Container.ID, opts)
if err != nil { if err != nil {
errCh <- fmt.Errorf("stop container '%s': %w", mc.Container.ID, err) errCh <- fmt.Errorf("stop container '%s': %w", mc.Container.ID, err)
} }
}() })
} }
go func() { go func() {
@@ -323,16 +315,12 @@ func (cli *Client) StartService(ctx context.Context, id string) error {
// Start all containers on all machines that belong to the service. // Start all containers on all machines that belong to the service.
for _, mc := range svc.Containers { for _, mc := range svc.Containers {
wg.Add(1) wg.Go(func() {
go func() {
defer wg.Done()
err := cli.StartContainer(ctx, svc.ID, mc.Container.ID) err := cli.StartContainer(ctx, svc.ID, mc.Container.ID)
if err != nil { if err != nil {
errCh <- fmt.Errorf("start container '%s': %w", mc.Container.ID, err) errCh <- fmt.Errorf("start container '%s': %w", mc.Container.ID, err)
} }
}() })
} }
go func() { go func() {