Go confirm()

1 개요[ | ]

Go confirm()
Go
Copy
package main

import (
	"fmt"
	"log"
	"regexp"
)

func confirm() bool {
	var response string
	_, err := fmt.Scanln(&response)
	if err != nil {
		log.Fatal(err)
	}
	match, _ := regexp.MatchString("[yY][eE][sS]|[yY]", response)
	return match
}

func main() {
	fmt.Print("Are you sure you want to do this? [y/N] ")
	isYes := confirm()
	fmt.Println("isYes=", isYes)
}


2 같이 보기[ | ]