package main
import (
"bufio"
"fmt"
"os"
)
func main() {
for {
consolereader := bufio.NewReader(os.Stdin)
fmt.Print("Enter your name : ")
input, err := consolereader.ReadString('\n') // this will prompt the user for input
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(input)
}
}
golang Go中的地图声明
//Will declare a map of string keys, int values.
var timeZone = map[string]int{
"UTC": 0*60*60,
"EST": -5*60*60,
"CST": -6*60*60,
"MST": -7*60*60,
"PST": -8*60*60,
}
//You can create a set-like structure using a map by setting the value of each key to bool.
attended := map[string]bool{
"Ann": true,
"Bobby": true
}
//This is useful now because you can check for existence in the map
if attended[somePerson] { //Will return false if somePerson isn't in the map
fmt.Printf("%v was present.\n")
}