I have a simple function that looks like this:
func convertToRealNum(number interface{}) interface{}{
switch v := number.(type) {
default:
log.Fatal("unexpected type %T", v)
case sql.NullFloat64:
newNumber := number.Float64
case sql.NullInt64:
newNumber := number.Int64
}
return newNumber
}
number is either a NullFloat64
or a NullInt64
. If number is the type NullFloat64, I call number.Float64 on it and get back the value of the number as a Float64. If I try to call the same thing inside a function that takes number as an argument that is an interface{} I get the compile error:
number.Float64 undefined (type interface {} has no field or method Float64)
Inside the function, if I call reflect.TypeOf(number) it'll return NullFloat64, so it knows what type it is, but I can't call that types methods.