Mushi

switch3.go

Apr 25th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.47 KB | None | 0 0
  1. // controles switch3 switch.go
  2. package main
  3.  
  4. import (
  5.     "fmt"
  6.     "time"
  7. )
  8.  
  9. func tipo(i interface{}) string {
  10.     switch i.(type) {
  11.     case int:
  12.         return "inteiro"
  13.     case float32, float64:
  14.         return "real"
  15.     case string:
  16.         return "string"
  17.     case func():
  18.         return "função"
  19.     default:
  20.         return "não sei"
  21.     }
  22.  
  23. }
  24.  
  25. func main() {
  26.     fmt.Println(tipo(2.3))
  27.     fmt.Println(tipo(1))
  28.     fmt.Println(tipo("Opa"))
  29.     fmt.Println(tipo(func() {}))
  30.     fmt.Println(tipo(time.Now()))
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment