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

  1. package main
  2. import "fmt"
  3. type cat struct {
  4. name string
  5. }
  6. func typeExample(i []interface{}) {
  7. for _, x := range i {
  8. switch v := x.(type) {
  9. case int:
  10. fmt.Printf("%v is an int\n", v)
  11. case string:
  12. fmt.Printf("%v is a string\n", v)
  13. case bool:
  14. fmt.Printf("%v is a boolean\n", v)
  15. default:
  16. fmt.Printf("Unknown type %T\n", v)
  17. }
  18. }
  19. }
  20. func main() {
  21. c := cat{"oreo"}
  22. i := []interface{}{42, "The book club", true, c}
  23. typeExample(i)
  24. }