type assertion

An expression such as value.(string) that gets the concrete value out of an interface, if it really holds that type.

In more detail

The two-result form text, ok := value.(string) sets ok to false instead of panicking when the type is wrong, so prefer it. The one-result form panics on a mismatch. Use assertions where data enters as any and convert to typed values quickly.

Example

seconds, ok := value.(int)

Related terms

Taught in

References