《Go并发编程实战》学习基础

最近在学校,写论文写不下去,还是看书学学技术,夯实下并发编程这块

Go相关基础知识使用可从下面的代码中学到

func chatting(){
	inputReader := bufio.NewReader(os.Stdin)
	fmt.Println("Please input your name!")
	input, err := inputReader.ReadString('\n')
	if err != nil {
		fmt.Printf("An error occured:%s\n", err)
		os.Exit(1)
	} else {
		name := input[:len(input)-1]
		fmt.Printf("Hello, %s! what can i do for you!!!!\n", name)
	}
	for {
		input, err = inputReader.ReadString('\n')
		if err!=nil{
			fmt.Printf("An error occurred: %s\n", err)
			continue
		}
		input = input[:len(input)-1]
		input = strings.ToLower(input)
		switch input {
		case "":continue
		case "nothing", "bye" :
			fmt.Println("Bye!!!")
			os.Exit(0)
		default:
			fmt.Println("Sorry! I didn't catch you")
		}
	}
}
原文地址:https://www.cnblogs.com/lvpengbo/p/15540319.html