a guest Mar 21st, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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]
  6. //if someTimeZone doesn't exist, seconds will be set to 0, and ok will be set to false.
  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. }
  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]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand