Skip to content

Commit

Permalink
fix: StdCopy into io.Pipe into bufio.Scanner
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap committed Nov 24, 2024
1 parent 0e3d41a commit 239e4df
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bufio"
"context"
"flag"
"io"
Expand Down Expand Up @@ -71,9 +72,19 @@ func containerStart(ctx context.Context, logger *slog.Logger, client *client.Cli
}

go func() {
_, err = stdcopy.StdCopy(reconn, reconn, readCloser)
if err != nil {
logger.Error("cannot write to pipe topic", "err", err)
r, w := io.Pipe()
go func() {
_, err = stdcopy.StdCopy(w, w, readCloser)
if err != nil {
logger.Error("cannot write to pipe topic", "err", err)
}
}()
scanner := bufio.NewScanner(r)
for {
for scanner.Scan() {
line := scanner.Text()
reconn.Write([]byte(line + "\n"))
}
}
}()

Expand Down

0 comments on commit 239e4df

Please sign in to comment.