golang typecast interface to int code example
Example: golang interface to int
var myInt interface{}
myInt = 8
toInt, ok := myInt.(int)
fmt.Println(toInt, ok) // 8 true
toString, ok := myInt.(string)
fmt.Println(toString, ok) // "" false
var myInt interface{}
myInt = 8
toInt, ok := myInt.(int)
fmt.Println(toInt, ok) // 8 true
toString, ok := myInt.(string)
fmt.Println(toString, ok) // "" false