Pretend using the universal any type interface{} in a function parameter. Say you work with JSON values and you want to get the type of them in order to process them properly.
A type switch may help you because you know the structure/types you get and therefore can safely assume which types you get. (see type switch )
In the example you also see a very handy print function. fmt.Printf("%v\n", res) eventually you know the printf function from C/C++. However the %v let's you print any type you want. Additionally with classes you might want to use %+v to also see the properties.
Pretend using the universal any type
interface{}
in a function parameter. Say you work with JSON values and you want to get the type of them in order to process them properly.A type switch may help you because you know the structure/types you get and therefore can safely assume which types you get. (see type switch )
In the example you also see a very handy print function.
fmt.Printf("%v\n", res)
eventually you know the printf function from C/C++. However the%v
let's you print any type you want. Additionally with classes you might want to use%+v
to also see the properties.Ahhh interesting, I see this is quite helpful. I'll need to use this in a little toy app to really cement the concept