package main
import (
"fmt"
"time"
)
func main() {
switch time.Now().Weekday().String() {
case "Monday", "Tuesday", "Wednesday", "Thursday", "Friday":
fmt.Println("it is time to work")
fmt.Println(time.Now().Weekday().String())
default:
fmt.Println(time.Now().Weekday().String())
}
}
从switch语句调用函数时,无需更改表达式即可修改其逻辑,因为你始终会验证函数返回的内容。
package main
import (
"fmt"
"regexp"
)
func main() {
var email = regexp.MustCompile(`^[^@]+@[^@.]+\.[^@.]+`)
var phone = regexp.MustCompile(`^[0-9][0-9]+`)
contact := "foo@bar.cc"
// contact := strconv.Itoa(234)
fmt.Printf("%T\n", contact)
switch {