Standard library / net
net.Pipe()
Create a synchronous in-memory full-duplex connection pair, without network sockets or internal buffering. Expected stdout: 'Go\n'.
Formal Syntax & Structure
go syntaxgo
func Pipe() (Conn, Conn)Return Value
(Conn, Conn)
Operation result; check errors and validity indicators when returned.
Working Example
Example Snippetgo
package main
import ( "fmt" "io" "net")
func main() { a, b := net.Pipe() defer a.Close() defer b.Close() done := make(chan error, 1) go func() { _, e := a.Write([]byte("Go")); done <- e }() buf := make([]byte, 2) must(io.ReadFull(b, buf)) check(<-done) fmt.Println(string(buf))}
func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}