Standard library / io
io.ReadWriteCloser
Combines read, write and close for duplex streams; ownership and concurrency depend on implementation. Expected stdout: 'ok <nil>\n'.
Formal Syntax & Structure
go syntaxgo
type ReadWriteCloser interface { Reader Writer Closer}Working Example
Example Snippetgo
package main
import ( "bytes" "fmt" "io" "strings")
func main() { var b bytes.Buffer var rw io.ReadWriteCloser = struct { *bytes.Buffer io.Closer }{&b, io.NopCloser(strings.NewReader(""))} rw.Write([]byte("ok")) p, _ := io.ReadAll(rw) fmt.Println(string(p), rw.Close())}