Exercises & activities from the go workshop provided by Packt: https://courses.packtpub.com/courses/go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

41 lines
536 B

package main
import "fmt"
func getData() []interface{} {
return []interface{}{
1,
3.14,
"hello",
true,
struct{}{},
}
}
func typeCheck(v interface{}) string {
switch v.(type) {
case string:
return "string"
case bool:
return "bool"
case float32, float64:
return "float"
case int, int32, int64:
return "int"
default:
return "unknown"
}
}
func main() {
data := getData()
for i := 0; i < len(data); i++ {
fmt.Printf("%v is %v\n", data[i], typeCheck(data[i]))
}
}