Handling Long User Input
With the fmt.Scan function, it won't take our input when we use spaces. We will have to go for another solution if we want longer user input values with spaces.
We have to use the package bufio where we can create a new reader.
reader := bufio.NewReader(os.Stdin)The os.Stdin input parameter is simply our command line.
In a next step, we can use the reader to read the string the user entered.
// the parameter defines where it should stop reading
text, err := reader.ReadString('\n')
// line break still inside the text so we have to remove it
text = strings.TrimSuffix(text, "\n") // removes the suffix from our given s
text = strings.TrimSuffix(text, "\r") // also remove /r because windows uses n+r for line break /n/r
return textLast updated