Safe Type Assertions

2025-01-152 minTech Related
#golang

Avoid panics using comma-ok.

Prevent panics automatically.

Example:

s, ok := v.(string)
if ok {
    fmt.Println(s)
}