本文整理汇总了Golang中io.PipeReader.ReadString方法的典型用法代码示例。如果您正苦于以下问题:Golang PipeReader.ReadString方法的具体用法?Golang PipeReader.ReadString怎么用?Golang PipeReader.ReadString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.PipeReader
的用法示例。
在下文中一共展示了PipeReader.ReadString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: startReading
// startReading starts a goroutine receiving the lines out of the reader
// in the background and passing them to a created string channel. This
// will used in the assertions.
func startReading(c *gc.C, tailer *tailer.Tailer, reader *io.PipeReader, writer *io.PipeWriter) chan string {
linec := make(chan string)
// Start goroutine for reading.
go func() {
defer close(linec)
reader := bufio.NewReader(reader)
for {
line, err := reader.ReadString('\n')
switch err {
case nil:
linec <- line
case io.EOF:
return
default:
c.Fail()
}
}
}()
// Close writer when tailer is stopped or has an error. Tailer using
// components can do it the same way.
go func() {
tailer.Wait()
writer.Close()
}()
return linec
}