《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")
		}
	}
}
posted @ 2021-11-11 15:55  布尔先生  阅读(110)  评论(0编辑  收藏  举报