inf3rno
0
Q:

safe cast golang

s, ok := v.(string)
if !ok {
    // the assertion failed.
}

// OR //

switch t := v.(type) {
case string:
    // t is a string
case int :
    // t is an int
default:
    // t is some other type that we didn't name.
}
0

Related

New to Communities?

Join the community