Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. switch v := myInterface.(type) {
  2. case int:
  3. // v is an int here, so e.g. v + 1 is possible.
  4. fmt.Printf("Integer: %v", v)
  5. case float64:
  6. // v is a float64 here, so e.g. v + 1.0 is possible.
  7. fmt.Printf("Float64: %v", v)
  8. case string:
  9. // v is a string here, so e.g. v + " Yeah!" is possible.
  10. fmt.Printf("String: %v", v)
  11. default:
  12. // And here I'm feeling dumb. ;)
  13. fmt.Printf("I don't know, ask stackoverflow.")
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement