Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package main
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. func switches() {
  7. i := 2
  8. fmt.Print("Write ", i, " as ")
  9. switch i {
  10. case 1:
  11. fmt.Println("one")
  12. case 2:
  13. fmt.Println("two")
  14. case 3:
  15. fmt.Println("three")
  16. }
  17. switch time.Now().Weekday() {
  18. case time.Saturday, time.Sunday:
  19. fmt.Println("It's the weekend")
  20. default:
  21. fmt.Println("It's a weekday")
  22. }
  23. t := time.Now()
  24. switch {
  25. case t.Hour() < 12:
  26. fmt.Println("It's before noon")
  27. default:
  28. fmt.Println("It's afternoon")
  29. }
  30. whatAmI := func(i interface{}) {
  31. switch t := i.(type) {
  32. case bool:
  33. fmt.Println("I'm a bool")
  34. case int:
  35. fmt.Println("I'm an int")
  36. default:
  37. fmt.Printf("Don't know type %T\n", t)
  38. }
  39. }
  40. whatAmI(true)
  41. whatAmI(1)
  42. whatAmI("hey")
  43. }