Reading User Input in Go

Learn how to take user input and display it in a Go program using bufio and os packages.

Reading User Input in Go
Photo by Nikita / Unsplash

Learn how to take user input and display it in a Go program using bufio and os packages.

package main

import (
    "bufio"
    "fmt"
    "os"
)

func main() {
    fmt.Print("Enter something: ")
    reader := bufio.NewReader(os.Stdin)
    userInput, _ := reader.ReadString('\n')
    fmt.Println("You entered:", userInput)
}