package main import ( "io" "os" ) func main() { pr, pw := io.Pipe() go func() { defer pw.Close() pw.Write([]byte("hello")) }() io.Copy(os.Stdout, pr) }
package main import ( "io" "os" "time" ) func main() { pr, pw := io.Pipe() go func() { defer pw.Close() for i := 0; i < 10; i++ { pw.Write([]byte("tick\n")) time.Sleep(time.Second) } }() io.Copy(os.Stdout, pr) }In this example, the writer writes the string "tick\n" to the pipe every second for 10 seconds. The `io.Copy()` function is used to copy the contents of the pipe to `os.Stdout`. The `io` package is the standard library package that contains the `PipeWriter` type.