For what I understand type assertion can only be used in interfaces and basically check if a determined type implements the interface.
I am having some weird scenarios:
func binder(value interface{}) {
// Does not work
valueInt, ok := value.(int)
// Works
valueInt, ok := value.(float64)
// Does not work
coordinates, ok := value.([]int)
// Does not work
coordinates, ok := value.([]float64)
}
Basically, my value
is an empty interface and I am getting from a json.Unmarshall
.
Scenario 1
when I pass a simple integer it does not work but if I check if is a float it works...
Scenario 2
When I pass an array of int or floats does not work! As you can see when I am debugging I am receiving an array but for some reason assertion does not work.