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.
 

31 lines
488 B

package main
import "fmt"
type cat struct {
name string
}
func typeExample(i []interface{}) {
for _, x := range i {
switch v := x.(type) {
case int:
fmt.Printf("%v is an int\n", v)
case string:
fmt.Printf("%v is a string\n", v)
case bool:
fmt.Printf("%v is a boolean\n", v)
default:
fmt.Printf("Unknown type %T\n", v)
}
}
}
func main() {
c := cat{"oreo"}
i := []interface{}{42, "The book club", true, c}
typeExample(i)
}