Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Using multiple assignment, you can distinguish a missing entry from a zero value.
- var seconds int
- var ok bool
- seconds, ok = timeZone[someTimeZone]
- //if someTimeZone doesn't exist, seconds will be set to 0, and ok will be set to false.
- //Example:
- func offset(tz string) int {
- if seconds, ok := timeZone[tz]; ok {
- return seconds
- }
- log.Println("unknown time zone:", tz)
- return 0
- }
- //If you just want to check for existence and don't want to assign a value, use the blank identifier.
- _, present = timeZone[tz]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement