1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-21 13:23:07 +01:00

chore: uses wg.Go where possible (#4074)

This commit is contained in:
Amir Raminfar
2025-08-15 08:29:25 -07:00
committed by GitHub
parent af93918f8c
commit 7be0515648
5 changed files with 27 additions and 47 deletions

View File

@@ -87,24 +87,21 @@ func (a *agentService) Exec(ctx context.Context, container container.Container,
}
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
wg.Go(func() {
if _, err := io.Copy(containerWriter, stdin); err != nil {
log.Error().Err(err).Msg("error while reading from ws using agent")
}
cancel()
containerWriter.Close()
}()
})
go func() {
defer wg.Done()
wg.Go(func() {
if _, err := stdcopy.StdCopy(stdout, stdout, containerReader); err != nil {
log.Error().Err(err).Msg("error while writing to ws using agent")
}
cancel()
}()
})
wg.Wait()

View File

@@ -120,19 +120,17 @@ func (d *DockerClientService) Attach(ctx context.Context, container container.Co
}
var wg sync.WaitGroup
wg.Add(2)
go func() {
wg.Go(func() {
defer wg.Done()
if _, err := io.Copy(containerWriter, stdin); err != nil {
log.Error().Err(err).Msg("error while reading from ws")
}
cancel()
containerWriter.Close()
}()
})
go func() {
defer wg.Done()
wg.Go(func() {
if container.Tty {
if _, err := io.Copy(stdout, containerReader); err != nil {
log.Error().Err(err).Msg("error while writing to ws")
@@ -143,7 +141,7 @@ func (d *DockerClientService) Attach(ctx context.Context, container container.Co
}
}
cancel()
}()
})
wg.Wait()
@@ -159,24 +157,20 @@ func (d *DockerClientService) Exec(ctx context.Context, container container.Cont
}
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
wg.Go(func() {
if _, err := io.Copy(containerWriter, stdin); err != nil {
log.Error().Err(err).Msg("error while reading from ws")
}
cancel()
containerWriter.Close()
}()
})
go func() {
defer wg.Done()
wg.Go(func() {
if _, err := stdcopy.StdCopy(stdout, stdout, containerReader); err != nil {
log.Error().Err(err).Msg("error while writing to ws")
}
cancel()
}()
})
wg.Wait()

View File

@@ -101,24 +101,21 @@ func (k *K8sClientService) Attach(ctx context.Context, container container.Conta
}
var wg sync.WaitGroup
wg.Add(2)
go func() {
wg.Go(func() {
defer writer.Close()
defer cancel()
defer wg.Done()
if _, err := io.Copy(writer, stdin); err != nil {
log.Error().Err(err).Msg("error copying stdin")
}
}()
})
go func() {
wg.Go(func() {
defer cancel()
defer wg.Done()
if _, err := io.Copy(stdout, reader); err != nil {
log.Error().Err(err).Msg("error copying stdout")
}
}()
})
wg.Wait()
return nil
@@ -133,24 +130,21 @@ func (k *K8sClientService) Exec(ctx context.Context, container container.Contain
}
var wg sync.WaitGroup
wg.Add(2)
go func() {
wg.Go(func() {
defer writer.Close()
defer cancel()
defer wg.Done()
if _, err := io.Copy(writer, stdin); err != nil {
log.Error().Err(err).Msg("error copying stdin")
}
}()
})
go func() {
wg.Go(func() {
defer cancel()
defer wg.Done()
if _, err := io.Copy(stdout, reader); err != nil {
log.Error().Err(err).Msg("error copying stdout")
}
}()
})
wg.Wait()
return nil