Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. //Using multiple assignment, you can distinguish a missing entry from a zero value.
  2. var seconds int
  3. var ok bool
  4. seconds, ok = timeZone[someTimeZone]
  5.  
  6. //if someTimeZone doesn't exist, seconds will be set to 0, and ok will be set to false.
  7.  
  8. //Example:
  9. func offset(tz string) int {
  10. if seconds, ok := timeZone[tz]; ok {
  11. return seconds
  12. }
  13. log.Println("unknown time zone:", tz)
  14. return 0
  15. }
  16.  
  17. //If you just want to check for existence and don't want to assign a value, use the blank identifier.
  18. _, present = timeZone[tz]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement