I am considering this simple code:
package main
import (
"fmt"
"bufio"
"io"
"os"
)
var in *bufio.Reader
var out io.Writer
func init() {
in = bufio.NewReader(os.Stdin)
out = os.Stdout
}
func main() {
str, err := in.ReadString('
')
fmt.Println("str: ", str, "err: ", err)
}
I am using IntelliJ with the Go plugin. My version of Go is 1.8. If I simply run the code there is no problem: str will be the same as the string I put, and err will be < nil >. If I debug the code I will not have the chance to put anything as input and I will have the following output:
API server listening at: 127.0.0.1:44824
str: err: EOF
I have no idea of what is happening: what is the first line for? How is it generated? And why the terminal does not "block" to let me write the input? And why err is "EOF" (it is like the part in which I have to put text is simply skipped: why?) ?
Last additional detail: I am executing this simple piece of code because I am actually trying to understand what is happening in a bigger project, in which a similar issue occurs. In fact, in that case I still have to put something by hand, and, again, if I debug the code it returns an error. In this case, however, the err variable contains a different thing: "error".