可以在 Goroutine 中使用 os.stdin 作为 Reader 吗?基本上我想要完成的是让用户在不阻塞主线程的情况下输入消息。
例子:
go func() {
for {
consolereader := bufio.NewReader(os.Stdin)
input, err := consolereader.ReadString('\n') // this will prompt the user for input
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(input)
}
}()