GO語言"io"包中"MultiWriter"函數的用法及代碼示例。
用法:
func MultiWriter(writers ...Writer) Writer
MultiWriter 創建一個寫入器,將其寫入複製到所有提供的寫入器,類似於 Unix tee(1) 命令。
每次寫入都會寫入每個列出的作者。如果列出的寫入器返回錯誤,則整個寫入操作將停止並返回錯誤;它不會繼續列表。
例子:
package main
import (
"bytes"
"fmt"
"io"
"log"
"strings"
)
func main() {
r := strings.NewReader("some io.Reader stream to be read\n")
var buf1, buf2 bytes.Buffer
w := io.MultiWriter(&buf1, &buf2)
if _, err := io.Copy(w, r); err != nil {
log.Fatal(err)
}
fmt.Print(buf1.String())
fmt.Print(buf2.String())
}
輸出:
some io.Reader stream to be read some io.Reader stream to be read
相關用法
- GO MultiReader用法及代碼示例
- GO Mul32用法及代碼示例
- GO Mul64用法及代碼示例
- GO MethodSet用法及代碼示例
- GO MakeFunc用法及代碼示例
- GO Mkdir用法及代碼示例
- GO Map用法及代碼示例
- GO MkdirTemp用法及代碼示例
- GO MakeTable用法及代碼示例
- GO Modf用法及代碼示例
- GO Mod用法及代碼示例
- GO MarshalIndent用法及代碼示例
- GO Marshal用法及代碼示例
- GO MatchString用法及代碼示例
- GO Month用法及代碼示例
- GO Match用法及代碼示例
- GO MkdirAll用法及代碼示例
- GO PutUvarint用法及代碼示例
- GO Scanner.Scan用法及代碼示例
- GO LeadingZeros32用法及代碼示例
注:本文由純淨天空篩選整理自golang.google.cn大神的英文原創作品 MultiWriter。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。