Andrew's Digital Garden

Ok in Go

Calling functions returns an ok variable, which can be used to check if the operation completed successfully.

This is known as the 'comma ok' idiom.

str, ok := value.(string) if ok { fmt.Printf("string value is: %q\n", str) } else { fmt.Printf("value is not a string\n") }

Or a shorter version:

if seconds, ok := timeZone[tz]; ok { return seconds }

[[20200720124245-go-maps]]

[[go]]

Referred in

Ok in Go