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:
@@ -290,10 +290,8 @@ func (s *server) ContainerExec(stream pb.AgentService_ContainerExecServer) error
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(2)
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
defer cancel()
|
||||
defer containerWriter.Close()
|
||||
for {
|
||||
@@ -306,10 +304,9 @@ func (s *server) ContainerExec(stream pb.AgentService_ContainerExecServer) error
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
defer cancel()
|
||||
buffer := make([]byte, 1024)
|
||||
for {
|
||||
@@ -322,7 +319,7 @@ func (s *server) ContainerExec(stream pb.AgentService_ContainerExecServer) error
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
|
||||
wg.Wait()
|
||||
|
||||
|
||||
@@ -238,12 +238,10 @@ func (k *K8sClient) ContainerEvents(ctx context.Context, ch chan<- container.Con
|
||||
}
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(len(watchers))
|
||||
|
||||
for _, watcher := range watchers {
|
||||
go func(w watch.Interface) {
|
||||
defer wg.Done()
|
||||
for event := range w.ResultChan() {
|
||||
wg.Go(func() {
|
||||
for event := range watcher.ResultChan() {
|
||||
log.Debug().Interface("event.type", event.Type).Msg("Received kubernetes event")
|
||||
pod, ok := event.Object.(*corev1.Pod)
|
||||
if !ok {
|
||||
@@ -270,7 +268,7 @@ func (k *K8sClient) ContainerEvents(ctx context.Context, ch chan<- container.Con
|
||||
}
|
||||
}
|
||||
}
|
||||
}(watcher)
|
||||
})
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user