标签:highlight 情况下 after pre time 很多 func pac ase
在有很多的if-then-else语句的情况下,go语言可以写成:
package main
import (
"fmt"
"time"
)
func main() {
t := time.Now()
switch true{
case t.Hour() < 12:
fmt.Println("Good morning!")
case t.Hour() < 17:
fmt.Println("Good afternoon.")
default:
fmt.Println("Good evening.")
}
}
标签:highlight 情况下 after pre time 很多 func pac ase
原文地址:https://www.cnblogs.com/AKUN-FYK/p/12937853.html