I know that you can call for text input from the user in go by doing the following:
fmt.Print("Enter text: ")
reader := bufio.NewReader(os.Stdin)
text, _ := reader.ReadString('
')
Which would ouput:
Enter text:
But is there a way to set an initial value for this input that the user could edit. For example, if the inital value was set to "english", then the output would be:
Enter text: english
My recommendation would be to put the default value in the prompt:
def := "english"
fmt.Printf("Enter text (%s): ", def)
reader := bufio.NewReader(os.Stdin)
text, _ := reader.ReadString('
')
text = strings.TrimSuffix(text, "
")
if text == "" {
text = def
}