I'm going to offer up a way to return a boolean based on passing an argument of a reflection Kinds to a local type receiver (because I couldn't find anything like this).
First, we declare our anonymous type of type reflect.Value:
type AnonymousType reflect.Value
Then we add a builder for our local type AnonymousType which can take in any potential type (as an interface):
func ToAnonymousType(obj interface{}) AnonymousType {
return AnonymousType(reflect.ValueOf(obj))
}
Then we add a function for our AnonymousType struct which asserts against a reflect.Kind:
func (a AnonymousType) IsA(typeToAssert reflect.Kind) bool {
return typeToAssert == reflect.Value(a).Kind()
}
This allows us to call the following:
var f float64 = 3.4
anon := ToAnonymousType(f)
if anon.IsA(reflect.String) {
fmt.Println("Its A String!")
} else if anon.IsA(reflect.Float32) {
fmt.Println("Its A Float32!")
} else if anon.IsA(reflect.Float64) {
fmt.Println("Its A Float64!")
} else {
fmt.Println("Failed")
}
Can see a longer, working version here:https://play.golang.org/p/EIAp0z62B7