Use io.Pipe() to create a connected pair of io.Reader and io.Writer that share a buffer, allowing one goroutine to write data while another reads it simultaneously.
pr, pw := io.Pipe()
// Writer goroutine
func() {
defer pw.Close()
pw.Write([]byte("hello"))
}()
// Reader goroutine
func() {
buf := make([]byte, 5)
pr.Read(buf)
fmt.Println(string(buf))
}()