Hello everyone, In this post, we will show you how to read the user-input in the Go programming language. The example program has been tested and shared in the same post.
Go – Reading the User-Input
package main import ( "bufio" "fmt" "os" ) // main function func main() { reader := bufio.NewReader(os.Stdin) fmt.Println("What is your name?") name, _ := reader.ReadString('\n') fmt.Println("Hello", name) }
Output
What is your name? Dinesh Krishnan Hello Dinesh Krishnan
References
- https://golang.org/doc/
- https://golang.org/pkg/
- https://golang.org/pkg/fmt/
- https://golang.org/pkg/fmt/#Println
- https://golang.org/pkg/bufio/
- https://golang.org/pkg/bufio/#NewReader
- https://golang.org/pkg/bufio/#Reader.ReadString
- https://golang.org/pkg/os/
More from my site
Hello, folks, I am a founder of idineshkrishnan.com. I love open source technologies, If you find my tutorials are useful, please consider making donations to these charities.