Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // controles switch3 switch.go
- package main
- import (
- "fmt"
- "time"
- )
- func tipo(i interface{}) string {
- switch i.(type) {
- case int:
- return "inteiro"
- case float32, float64:
- return "real"
- case string:
- return "string"
- case func():
- return "função"
- default:
- return "não sei"
- }
- }
- func main() {
- fmt.Println(tipo(2.3))
- fmt.Println(tipo(1))
- fmt.Println(tipo("Opa"))
- fmt.Println(tipo(func() {}))
- fmt.Println(tipo(time.Now()))
- }
Advertisement
Add Comment
Please, Sign In to add comment