Read_console

Read information from console is very important, here is a simple way to read message from conosle

fmt read

package main

import (
	"fmt"
)

func main() {
	var message string
	fmt.Print("Please input the message:")
	fmt.Scan(&message)
}

stdin read

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	fmt.Print("Input your name: ")
	name, err := reader.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(name)
}
Built with Hugo
Theme Stack designed by Jimmy