Thanks for that feedback @supportic, I was having trouble seeing how I'd use the type switch at this point. I'll keep it on the back burner for now, I'm planning to take a look at function syntax and data structures today so thanks for the links.
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.
Thanks for that feedback @supportic, I was having trouble seeing how I'd use the type switch at this point. I'll keep it on the back burner for now, I'm planning to take a look at function syntax and data structures today so thanks for the links.
Thanks for the welcome as well glad to be here 😁
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