I have the below code snippet:
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
fmt.Println("Enter your name")
name, err := reader.ReadString('\n') //THIS LINE
if err == nil {
fmt.Println("Hello " + name)
}
}
My question is, if I want to NOT use the := syntax (like I have at the first line of main()), how would I rewrite the ReadString() invocation with types?
I tried the following, with the corresponding errors:
var name string, err error = reader.ReadString('\n')->syntax error: unexpected comma at end of statementvar name, err string, error = reader.ReadString('\n')->syntax error: unexpected comma at end of statement- Taking a hint from Multiple variables of different types in one line in Go (without short variable declaration syntax) I also tried
var (name string, err error) = reader.ReadString('\n')which also gives the same error.
For the above linked question, the marked answer simply suggests using two lines for two different variable types. But how would that work for the return values of a function like ReadString()?