Standard library / io
io.MultiWriter()
Duplicates writes to each writer in order; stops on the first failure, so earlier destinations may already have changed. Expected stdout: '2 ok ok <nil>\n'.
Formal Syntax & Structure
go syntaxgo
func MultiWriter(writers ...Writer) WriterParameters & Attributes
| Name | Type | Description |
|---|---|---|
| writers | ...Writer | Destination writers in write order. |
Return Value
Writer
Duplicates writes to each writer in order; stops on the first failure, so earlier destinations may already have changed.
Working Example
Example Snippetgo
package main
import ( "bytes" "fmt" "io")
func main() { var a, b bytes.Buffer n, e := io.WriteString(io.MultiWriter(&a, &b), "ok") fmt.Println(n, a.String(), b.String(), e)}