56 lines
903 B
Go
56 lines
903 B
Go
![]() |
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"time"
|
||
|
"runtime"
|
||
|
)
|
||
|
|
||
|
func letsDefer(text string) {
|
||
|
defer fmt.Println(text)
|
||
|
fmt.Print("I have deferred: ")
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
fmt.Print("Go runs on ")
|
||
|
switch os := runtime.GOOS; os {
|
||
|
case "darwin":
|
||
|
fmt.Println("macOS.")
|
||
|
case "linux":
|
||
|
fmt.Println("Linux.")
|
||
|
default:
|
||
|
fmt.Printf("%s.\n", os)
|
||
|
}
|
||
|
|
||
|
fmt.Println("When's Saturday?")
|
||
|
today := time.Now().Weekday()
|
||
|
switch time.Saturday {
|
||
|
case today + 0:
|
||
|
fmt.Println("Today.")
|
||
|
case today + 1:
|
||
|
fmt.Println("Tomorrow.")
|
||
|
case today + 2:
|
||
|
fmt.Println("In two days.")
|
||
|
default:
|
||
|
fmt.Println("Too far away.")
|
||
|
}
|
||
|
|
||
|
t := time.Now()
|
||
|
switch {
|
||
|
case t.Hour() < 12:
|
||
|
fmt.Println("Good morning!")
|
||
|
case t.Hour() < 17:
|
||
|
fmt.Println("Good afternoon")
|
||
|
default:
|
||
|
fmt.Println("Good evening.")
|
||
|
}
|
||
|
|
||
|
letsDefer("Some stuff")
|
||
|
|
||
|
fmt.Println("Counting...")
|
||
|
for i:=0; i<10; i++ {
|
||
|
defer fmt.Println(i)
|
||
|
}
|
||
|
fmt.Println("Done!")
|
||
|
}
|